Dan Kaib
asked on
VBscript Application.Printout options not working.
I'm not a VB programmer but found a script that I'm trying to modify and execute.
On the .Application.Prinout line if any options are appended it fails with a compliation error with the message Expected Statement and code 800A0400. If I try it without any options it will execute. Are options allowed with this method?
Below is the code.
TIa,
Dan
On the .Application.Prinout line if any options are appended it fails with a compliation error with the message Expected Statement and code 800A0400. If I try it without any options it will execute. Are options allowed with this method?
Below is the code.
TIa,
Dan
Option Explicit
Dim objDoc, objFile, objFSO, objWord, strFile, strPDF, myFile
myFile = "C:\Documents and Settings\Administrator\My Documents\adr.doc"
' Create a File System object
Set objFSO = CreateObject( "Scripting.FileSystemObject" )
' Create a Word object
Set objWord = CreateObject( "Word.Application" )
With objWord
' True: make Word visible; False: invisible
.Visible = True
' Check if the Word document exists
If objFSO.FileExists( myFile ) Then
Set objFile = objFSO.GetFile( myFile )
strFile = objFile.Path
Else
WScript.Echo "FILE OPEN ERROR: The file does not exist" & vbCrLf
' Close Word
.Quit
'Exit Sub
'Exit
End If
' Build the fully qualified PDF file name
strPDF = objFSO.BuildPath( objFile.ParentFolder, _
objFSO.GetBaseName( objFile ) & ".pdf" )
' Open the Word document
.Documents.Open strFile
' Make the opened file the active document
Set objDoc = .ActiveDocument
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
.ActivePrinter = "CutePDF Writer"
.Application.Printout _
FileName:=strFile, Range:=wdPrintAllDocument, Item:= _
wdPrintDocumentContent, Copies:=1, Pages:="", _
PageType:=wdPrintAllPage, Collate:=True, Background:=False, _
PrinttoFile:=False, OutputFileName:=strPDF
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Close the active document
objDoc.Close
' Close Word
.Quit
End With
ASKER
Thanks for the reply,
I do not have Office 2007.
The options I want to use are as follows:
.Application.Printout _
FileName:=strFile, Range:=wdPrintAllDocument, Item:= _
wdPrintDocumentContent, Copies:=1, Pages:="", _
PageType:=wdPrintAllPage, Collate:=True, Background:=False, _
PrinttoFile:=False, OutputFileName:=strPDF
I do not have Office 2007.
The options I want to use are as follows:
.Application.Printout _
FileName:=strFile, Range:=wdPrintAllDocument,
wdPrintDocumentContent, Copies:=1, Pages:="", _
PageType:=wdPrintAllPage, Collate:=True, Background:=False, _
PrinttoFile:=False, OutputFileName:=strPDF
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for the reply,
I did not realize that the options would be printer specific. I've recorded some macros and they produce the same options, so I just figured it would be good to go.
I will check with cutepdf support. I've also tried win2pdf which is similar to cutepdf and it fails the same way.
Thanks for you help, I appreciate it,
Dan
I did not realize that the options would be printer specific. I've recorded some macros and they produce the same options, so I just figured it would be good to go.
I will check with cutepdf support. I've also tried win2pdf which is similar to cutepdf and it fails the same way.
Thanks for you help, I appreciate it,
Dan
I'd like to see you recordings if possible.
ASKER
Here is the macro created in Word, when it executes it prompts for the file name which is not what I want but you can see the options that it created:
Sub Macro2()
ActivePrinter = "CutePDF Writer"
Application.PrintOut FileName:="", Range:=wdPrintAllDocument, Item:= _
wdPrintDocumentContent, Copies:=1, Pages:="", PageType:=wdPrintAllPages, _
ManualDuplexPrint:=False, Collate:=True, Background:=True, PrintToFile:= _
False, PrintZoomColumn:=0, PrintZoomRow:=0, PrintZoomPaperWidth:=0, _
PrintZoomPaperHeight:=0
End Sub
What I am trying to do is print the Word document as a PDF from a VBscript where I can name the PDF files on the fly.
Thanks,
Dan
Sub Macro2()
ActivePrinter = "CutePDF Writer"
Application.PrintOut FileName:="", Range:=wdPrintAllDocument,
wdPrintDocumentContent, Copies:=1, Pages:="", PageType:=wdPrintAllPages,
ManualDuplexPrint:=False, Collate:=True, Background:=True, PrintToFile:= _
False, PrintZoomColumn:=0, PrintZoomRow:=0, PrintZoomPaperWidth:=0, _
PrintZoomPaperHeight:=0
End Sub
What I am trying to do is print the Word document as a PDF from a VBscript where I can name the PDF files on the fly.
Thanks,
Dan
Hi Dan,
Well the difference between the 2 that I can see is , OutputFileName:=strPDF and with cutepdf you have Background:=True as opposed to Background:=False in your original code.
Also cutepdf is adding PrintZoomColumn:=0, PrintZoomRow:=0, PrintZoomPaperWidth:=0, _
PrintZoomPaperHeight:=0
It might be any of them, but there is a possibility cutepdf does not support the OutputFilename being specified like that. All you can do is play around and see which one is causing you the grief.
Cheers,
Terry
Well the difference between the 2 that I can see is , OutputFileName:=strPDF and with cutepdf you have Background:=True as opposed to Background:=False in your original code.
Also cutepdf is adding PrintZoomColumn:=0, PrintZoomRow:=0, PrintZoomPaperWidth:=0, _
PrintZoomPaperHeight:=0
It might be any of them, but there is a possibility cutepdf does not support the OutputFilename being specified like that. All you can do is play around and see which one is causing you the grief.
Cheers,
Terry
ASKER
Hi Terry,
Thanks for the reply. I don't think any options work when trying it from within a VBscript.
On the .Application.Prinout line if any options are appended it fails with a compliation error with the message Expected Statement and code 800A0400.
I tried it with all the same options as the macro and still get the compiliation error. There is no option that I apply to the command that does not give me the compilation error above.
I found different software WIN2PDF that interfaces with the WIN32 API but it has to run from a VB program not a VBscript.
Thanks for all of your help, I appreciate it.
Dan
Thanks for the reply. I don't think any options work when trying it from within a VBscript.
On the .Application.Prinout line if any options are appended it fails with a compliation error with the message Expected Statement and code 800A0400.
I tried it with all the same options as the macro and still get the compiliation error. There is no option that I apply to the command that does not give me the compilation error above.
I found different software WIN2PDF that interfaces with the WIN32 API but it has to run from a VB program not a VBscript.
Thanks for all of your help, I appreciate it.
Dan
It looks like your converting word documents to PDF.
You can do that in office 2007 with the Office Add-in: Save as PDF but I'm assuming you don't have office 2007.