A
Alan
I am trying to print a file from VBA with the code found below.
What happens is that the printer monitor shows it as "Spooling", and
when I go to Word, where the file is open, it says "Please wait while
word finishes all pending print jobs." The file contains one word of
text, and it never prints.
The last thing shown in Debug is: "Closing document . . ."
What am I doing wrong? Thanks, Alan
Private Sub CreatePdfDocs()
Dim Word As Word.Application
Dim aWordFileName As String, i As Integer
Set Word = New Word.Application
On Error GoTo Finally
aWordFileName = "C:\Users\Alan\Desktop\Test.doc"
' Open a Word document
Debug.Print "Opening document . . . "
Word.Documents.Open Filename:=aWordFileName, Visible:=True
' Print it to PDF
Debug.Print "Printing . . ."
Word.Documents(aWordFileName).PrintOut To:="HP Deskjet D4200
series"
Debug.Print "Closing document . . ."
Word.Documents.Close SaveChanges:=False
Word.Quit
Set Word = Nothing
Exit Sub
Finally:
MsgBox "An error occurred" & vbCrLf & Err.Source & vbCrLf & _
"Error # " & Err.Number & ": " & Err.Description,
vbCritical
Word.Quit
Set Word = Nothing
End Sub
What happens is that the printer monitor shows it as "Spooling", and
when I go to Word, where the file is open, it says "Please wait while
word finishes all pending print jobs." The file contains one word of
text, and it never prints.
The last thing shown in Debug is: "Closing document . . ."
What am I doing wrong? Thanks, Alan
Private Sub CreatePdfDocs()
Dim Word As Word.Application
Dim aWordFileName As String, i As Integer
Set Word = New Word.Application
On Error GoTo Finally
aWordFileName = "C:\Users\Alan\Desktop\Test.doc"
' Open a Word document
Debug.Print "Opening document . . . "
Word.Documents.Open Filename:=aWordFileName, Visible:=True
' Print it to PDF
Debug.Print "Printing . . ."
Word.Documents(aWordFileName).PrintOut To:="HP Deskjet D4200
series"
Debug.Print "Closing document . . ."
Word.Documents.Close SaveChanges:=False
Word.Quit
Set Word = Nothing
Exit Sub
Finally:
MsgBox "An error occurred" & vbCrLf & Err.Source & vbCrLf & _
"Error # " & Err.Number & ": " & Err.Description,
vbCritical
Word.Quit
Set Word = Nothing
End Sub