Link to home
Start Free TrialLog in
Avatar of Genius123
Genius123Flag for United States of America

asked on

Print PDF using VB Script

Hello,

I use a customized Outlook form that runs VB Script.  I have a command button that opens up a Word template and prints it to a PDF file.  What happens though is when printing, the save PDF dialog box comes up.  I don't want that.  I want it to save it as a PDF automatically without the dialog box coming up.  Let's just say C:\test.pdf.  Here's the code that I currently use.

Sub CommandButtonShipLabelUSPS_Click()

On Error Resume Next

Dim strCurrentPrinter' As String

	Set objDoc2 = GetWordDocLabel("\\TGPS13VM1\drawing$\Jobs\Task_Templates\Ship-Ship Label USPS.dot")
    	Call FillFieldsShipLabel(objDoc2)
    	objDoc2.Application.Options.PrintBackground = False
    	objDoc2.Application.DisplayAlerts = False

if Item.UserProperties("PrintHold") = True then
  	Set objDoc2 = Nothing
  	Set strCurrentPrinter = Nothing
  	Set objWord2 = Nothing
	Exit Sub
end if

    	strCurrentPrinter = objDoc2.Application.ActivePrinter ' store the current active printer
    	objDoc2.Application.ActivePrinter = "Adobe PDF" ' change to another printer

    	objDoc2.PrintOut ' print the active sheet
	Call RestoreActivePrinter

	objDoc2.Application.DisplayAlerts = True
    	objDoc2.Application.Options.PrintBackground = True

objDoc2.Close wdDoNotSaveChanges
objWord2.Quit wdDoNotSaveChanges

	Set objDoc2 = Nothing
  	Set strCurrentPrinter = Nothing
  	Set objWord2 = Nothing

End Sub

Open in new window




Thank you,
Joel
Avatar of GrahamSkan
GrahamSkan
Flag of United Kingdom of Great Britain and Northern Ireland image

You need to specify the pdf file in the PrintOut line:
          objDoc2.PrintOut OutputFilename = "C:\MyFolder\Mydoc.pdf"

Open in new window

Avatar of Genius123

ASKER

Thank you.  Do you know how I would define the variable OutputFilename?  I just declared it like "Dim OutputFilename", but it doesn't work.  It still brings up the save dialog box.
ASKER CERTIFIED SOLUTION
Avatar of Steve Knight
Steve Knight
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you, this worked.