PDA

View Full Version : How to avoid print dialog box?



musicgold
11-03-2008, 01:37 PM
Hi,
I am trying to automate the steps required to convert a worksheet into a pdf document. I am using the following code. The code works fine if I eliminate ?prtofilename:=Filename? from the parameters for the Printout method. But then a print dialog box pops up, where I have to enter a filename for the file being saved. I want to avoid this step. I tried different ways but couldn?t achieve this. Could you suggest a solution?



Sub print_macro()

Dim Filename As String
Filename = "c:\ABC.pdf"

Application.ActivePrinter = "CutePDF Writer on CPW2:"

ActiveWindow.SelectedSheets.PrintOut Copies:=1, ActivePrinter:= _
"CutePDF Writer on CPW2:", PrintToFile:=False, Collate:=True, prtofilename:=Filename

End Sub


System: Windows XP
Excel 2003 Sp2

Thanks,

MG.

rbrhodes
11-03-2008, 10:31 PM
Hi MG, Did you try changing PrintToFile:=True ?


Sub print_macro()

Dim Filename As String
Filename = "c:\ABC.pdf"

Application.ActivePrinter = "CutePDF Writer on CPW2:"

ActiveWindow.SelectedSheets.PrintOut Copies:=1, ActivePrinter:= _
"CutePDF Writer on CPW2:", PrintToFile:=True, Collate:=True, prtofilename:=Filename

End Sub

musicgold
11-04-2008, 07:33 AM
rbrhodes,

Thanks. I had tried that option before, and the printing seemed automatic (with no Save As box appearing); however, the pdf file created by the code was corrupt. Adobe Acrobat was not able to open those files. I figured that may be there was something wrong with the vba code.

Thanks,
MG.

mdmackillop
11-04-2008, 11:02 AM
You can modify registry settings to automate Cute PDF printing. See here (http://www.cutepdf.com/Solutions/pdfwriter2.asp#Module)

musicgold
11-05-2008, 03:58 PM
mdmackillop,

Thanks.

1. I have a free version of Cutepdf. Do those registry edits work with the free version?

2. I tried to do the changes suggested by the document on Cutepdf's website using Regedit, but couldn't find those particular variables ( e.g. BypassSaveAs).


Thanks,

MG.