Just started learning about VBA. Despite following the codes below from the tutorials, I still get the "Run-time error 91: Object variable or With block variable not set" error . Don't know where I am going wrong and I would appreciate your advice.
Many thanks in advance.
Rick.
My codes are:
Sub OpenWordDoc()
Dim wdapp As Word.Application
Dim wddoc As Word.Document
On Error Resume Next
Set wdapp = GetObject(, "Word.Application")
If Err.Number <> 0 Then 'Word isn't already running
Set wdapp = GetObject("Word.Application")
End If
On Error GoTo 0
wdapp.Documents.Open ("C:\Documents.docx")
Set wddoc = wdapp.ActiveDocument
wdapp.Visible = True
End Sub
Many thanks in advance.
Rick.
My codes are:
Sub OpenWordDoc()
Dim wdapp As Word.Application
Dim wddoc As Word.Document
On Error Resume Next
Set wdapp = GetObject(, "Word.Application")
If Err.Number <> 0 Then 'Word isn't already running
Set wdapp = GetObject("Word.Application")
End If
On Error GoTo 0
wdapp.Documents.Open ("C:\Documents.docx")
Set wddoc = wdapp.ActiveDocument
wdapp.Visible = True
End Sub