I have two codes that create and/or open a Word document from Excel, both contain similar coding including the syntax
Set Word = GetObject(, "Word.Application")
In one sub the document opens perfectly fine and in the other sub I get a runtime error 429 on the above syntax, but only when Word is not open. When Word is open, the function is working just fine.
Part of the code of working sub
Cells(ActiveCell.Row, ActiveSheet.Range("zz_templates").Column).Activate
Range("zz_preventloop").Value = "x"
Application.ScreenUpdating = False
Dim DocType As String
If Range("zz_officeversion").Value = "previous to 2007" Then
DocType = ".doc"
Else
DocType = ".docx"
End If
Dim filename As String
filename = Range("zz_envelope_documents").Value + "/" + Cells(ActiveCell.Row, ActiveSheet.Range("zz_locations_doc").Column).Value + "/"
filename = filename + Cells(ActiveCell.Row, ActiveSheet.Range("zz_eDMSname").Column).Value + DocType
If Len(filename) < 256 Then
'check the document type
If Cells(ActiveCell.Row, ActiveSheet.Range("zz_doctype_doc").Column).Value = ".url" Then ''Opening the .url shortcut
On Error Resume Next
ActiveWorkbook.FollowHyperlink Range("zz_envelope_templates").Value + "/" + ActiveSheet.Cells(ActiveCell.Row, ActiveSheet.Range("zz_locations_temp").Column).Value + "/" _
+ ActiveSheet.Cells(ActiveCell.Row, ActiveSheet.Range("zz_hidden_eDMStemp").Column).Value + ".url", NewWindow:=True
Else
If Cells(ActiveCell.Row, ActiveSheet.Range("zz_doctype_doc").Column).Value = ".docx" Then
Application.Calculate
On Error Resume Next
Set Word = GetObject(, "Word.Application")
If Word Is Nothing Then
Set Word = CreateObject("Word.Application")
End If
Rest of sub
Part of code of non-working sub
Cells(ActiveCell.Row, ActiveSheet.Range("zz_templates").Column).Activate
Range("zz_preventloop").Value = "x"
Application.ScreenUpdating = False
Dim DocType As String
If Range("zz_officeversion").Value = "previous to 2007" Then
DocType = ".doc"
Else
DocType = ".docx"
End If
'check the document type
If Cells(ActiveCell.Row, ActiveSheet.Range("zz_doctype_template").Column).Value = ".url" Then
''Opening the .url shortcut
On Error Resume Next
ActiveWorkbook.FollowHyperlink Range("zz_envelope_templates").Value + "/" + ActiveSheet.Cells(ActiveCell.Row, ActiveSheet.Range("zz_locations_temp").Column).Value + "/" _
+ ActiveSheet.Cells(ActiveCell.Row, ActiveSheet.Range("zz_hidden_eDMStemp").Column).Value + ".url", NewWindow:=True
Else
If Cells(ActiveCell.Row, ActiveSheet.Range("zz_doctype_template").Column).Value = ".docx" Then
Set Word = GetObject(, "Word.Application")
If Word Is Nothing Then
Set Word = CreateObject("Word.Application")
End If
Rest of sub
What am I overlooking in the second function that it is not working when Word is not open?