Reputation: 660
As the title says, I'm receiving this error on compile:
https://i.sstatic.net/sWmTT.png
My code:
Sub PasteToWord()
Range("A1").Select
Do Until IsEmpty(ActiveCell)
Dim AppWord As Word.Application
Set AppWord = CreateObject("Word.Application")
AppWord.Visible = True
Sheets("Sheet1").Range(ActiveCell).Copy
AppWord.Documents.Add
AppWord.Selection.Paste
Application.CutCopyMode = False
AppWord.SaveAs2 "C:\Docs\MyDoc.pdf", 17
Set AppWord = Nothing
AppWord.Quit
Loop
End Sub
The debugger is highlighting .SaveAs2
as the root of the issue.
I've gone in to Excel VBA's References menu, and made sure both "Microsoft Office 14.0 Object Library" and "Microsoft Word 14.0 Object Library" are checked.
What could be causing the issue here? Thanks in advance.
Upvotes: 1
Views: 1166
Reputation: 17647
.SaveAs2
is a method of a document object, not an application object.
Try
AppWord.ActiveDocument.SaveAs2 "C:\Docs\MyDoc.pdf", 17
Upvotes: 1