Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 creator: 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 'visible. 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 Else wdDoc.BuiltinDocumentProperties("Author") _ = AuthorName End If wdDoc.Activate 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 .cClearCache End With wdDoc.ActiveWindow.PrintOut copies:=1, ActivePrinter:="PDFCreator" Do Until pdfjob.cCountOfPrintjobs = 1 DoEvents Loop pdfjob.cPrinterStop = False Do Until pdfjob.cCountOfPrintjobs = 0 DoEvents Loop pdfjob.cClose Set pdfjob = Nothing 'Return value of the function; signifies successful completion. OpenSelectedWordDocument = True 'ExitPoint: ' Set wdDoc = Nothing ' Set wdApp = Nothing ' ' Exit Function 'ErrorHandler: ' 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. Navin |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
changing active printer for Word.
Navin,
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 .Execute End With _________________________________ Steve "navin" wrote in message ups.com... 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 creator: 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 'visible. 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 Else wdDoc.BuiltinDocumentProperties("Author") _ = AuthorName End If wdDoc.Activate 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 .cClearCache End With wdDoc.ActiveWindow.PrintOut copies:=1, ActivePrinter:="PDFCreator" Do Until pdfjob.cCountOfPrintjobs = 1 DoEvents Loop pdfjob.cPrinterStop = False Do Until pdfjob.cCountOfPrintjobs = 0 DoEvents Loop pdfjob.cClose Set pdfjob = Nothing 'Return value of the function; signifies successful completion. OpenSelectedWordDocument = True 'ExitPoint: ' Set wdDoc = Nothing ' Set wdApp = Nothing ' ' Exit Function 'ErrorHandler: ' 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. Navin |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
active Printer | Excel Programming | |||
Setting the active printer | Excel Programming | |||
active printer | Excel Programming | |||
Active printer | Excel Programming | |||
Resetting the Active Printer | Excel Programming |