changing active printer for Word.



Hi All,

I am trying to convert a word document to pdf in Excel. It converts
the word document into PDF if i manually change the default printer to
PDF printer, but when i try to assign the printer name using
ActivePrinter, it gives error: "Named Argument not found". Can anybody
please tell me, after opening the word document using excel VBA, how
can change the activeprinter for it.

Below is the code which i am using to convert the word to PDF with PDF

Function OpenPOWordDocument _
(FullNameOfDoc As String, _
Optional AuthorName As String) As Boolean

Dim wdApp As Object
Dim wdDoc As Object
Dim pdfjob As Object
Dim sPDFName As String
Dim sPDFPath As String

'On Error GoTo ErrorHandler

OpenPOWordDocument = False

'Open a new instance of Word and make it
Set wdApp = CreateObject("Word.Application")
sPDFName = "testPDF.pdf"
sPDFPath = "D:\PO Copies"
wdApp.Visible = True

Set wdDoc = wdApp.Documents.Open(FileName:=FullNameOfDoc)

If AuthorName = "" Then
wdDoc.BuiltinDocumentProperties("Author") _
= Application.UserName
wdDoc.BuiltinDocumentProperties("Author") _
= AuthorName
End If
Set pdfjob = CreateObject("PDFCreator.clsPDFCreator")

With pdfjob
If .cStart("/NoProcessingAtStartup") = False Then
MsgBox "Can't initialize PDFCreator.", vbCritical + _
vbOKOnly, "PrtPDFCreator"
Exit Function
End If
.cOption("UseAutosave") = 1
.cOption("UseAutosaveDirectory") = 1
.cOption("AutosaveDirectory") = sPDFPath
.cOption("AutosaveFilename") = checklength
.cOption("AutosaveFormat") = 0 ' 0 = PDF
End With

wdDoc.ActiveWindow.PrintOut copies:=1, ActivePrinter:="PDFCreator"
Do Until pdfjob.cCountOfPrintjobs = 1
pdfjob.cPrinterStop = False
Do Until pdfjob.cCountOfPrintjobs = 0
Set pdfjob = Nothing

'Return value of the function; signifies successful completion.
OpenSelectedWordDocument = True


' Set wdDoc = Nothing
' Set wdApp = Nothing
' Exit Function

' MsgBox "Sorry, unable to open the Word file. The following error
occurred:" _
' & vbCrLf & Err.Number & vbCrLf & Err.Description

' Resume ExitPoint

End Function

Thanks for the help.




Steve Yandl


This is part of a workaround that did the job for me from a vbScript. I
used it to print text files on an installed printer that wasn't the default
printer but I suspect it will work for you with PDFCreator.


Const wdDialogFilePrintSetup = 97
strPrntChoice = "PDFCreator"

With wdApp.Application.Dialogs(wdDialogFilePrintSetup)
.Printer = strPrntChoice
.DoNotSetAsSysDefault = True
End With


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question