PC Review


Reply
Thread Tools Rate Thread

changing active printer for Word.

 
 
navin
Guest
Posts: n/a
 
      27th Sep 2007
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 With Quote
 
 
 
 
Steve Yandl
Guest
Posts: n/a
 
      27th Sep 2007
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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 With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Changing active windows via task bar pops up other active windows =?Utf-8?B?TGluZGE=?= Windows XP General 1 29th Aug 2007 07:32 PM
Printer's quotes not changing when new font applied - Word 2007, V =?Utf-8?B?SWFuIEou?= Microsoft Word Document Management 0 29th Jun 2007 02:38 PM
Changing Printer Trays on Networked printers - Word 2003 =?Utf-8?B?Uy5IYW5hZ2Fu?= Microsoft Word Document Management 1 10th Oct 2006 01:41 AM
Windows XP Pro keeps changing the Printer Port for network printer =?Utf-8?B?QmlsbCBH?= Windows XP Print / Fax 0 12th Mar 2005 04:21 PM
Changing the active printer via VBA macro Markus Zänglein Microsoft Outlook VBA Programming 7 14th Jan 2005 02:08 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:05 PM.