Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 32
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 284
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
active Printer Libby Excel Programming 3 June 21st 07 06:45 PM
Setting the active printer Boog Excel Programming 0 June 5th 06 04:10 AM
active printer Gixxer_J_97[_2_] Excel Programming 2 June 29th 05 02:24 PM
Active printer Marijan Glavac Excel Programming 1 September 29th 04 01:41 PM
Resetting the Active Printer Sue[_5_] Excel Programming 1 January 15th 04 01:20 AM


All times are GMT +1. The time now is 07:10 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"