I was wondering if anyone could help with this piece of code. At the most basic level what I am trying to do is open a word document from Excel, and then control that word document through VBA, to either print/complete a mail merge, or do anything else that might be required. The code I have is as below:
Dim X As Object, y As Object, z As String On Error Resume Next Set X = GetObject(, "Word.Application") If Err.Number = 429 Then Set X = CreateObject("Word.Application") End If z = "myfilename&path.doc" X.Visible = True X.Activate Set y = X.Documents(z) If y Is Nothing Then Set y = X.Documents.Open(z) End If On Error GoTo 0 fname = "myfilename&path.doc" Activedocument.SaveAs FileName:=fname, FileFormat:= _ xlNormal, Password:="", WriteResPassword:="", ReadOnlyRecommended:=False _ , CreateBackup:=False
Up to the red part, the code works fine i.e. it at the very least opens the word document I want to control. But once I get to the red piece of code I get an error message "Run time error 424 - object required". It seems to me as though maybe the document isn't properly activated. I have had a look on other forums, and changed the code to X.Activedocument etc, but this doesn't seem to make any difference. I hope someone can help with this.