Macro to print to PDF and save using bookmark name

M

MIrving

I am using Word 97 and would like to write a macro that achieves the
following in an active document:

1. Active document is printed in PDF format (usually this involves going to
File -> Print -> Adobe PDFwriter)

2. When prompted to put in the filename for the PDF file, the filename is
taken from a bookmark (named 'filename') in the active document.

I would greatly appreciate any suggestions.
 
D

Doug Robbins - Word MVP

See the article "Changing the selected (current) printer in Word without
changing the system default printer" at:

http://www.word.mvps.org/FAQs/MacrosVBA/ChangeCurPrinter.htm

The easiest way to deal with the filename would be to save the file with the
name obtained by getting the .Range.Text of the bookmark, then do the print
to Adobe PDF (in the properties for the Adobe PDF printer, you can turn off
the request for a filename and it will then just use the name of the
document), then close the file and use the VBA Kill statement to delete the
file that you saved with the bookmark name if necessary.


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
M

MIrving

Thank you Doug.

I came across a code on the internet for printing to Adobe Distiller. I was
hoping I could modify it and use it with PDF995 instead of Adobe (I have
confirmed that all users that would run the macro have PDF995 whereas it
turns out less than half have Adobe Acrobat). I have cobbled together the
following:

Sub pdf()
Dim PDFFileName As String

'Define the path and filename
PDFFileName = ActiveDocument.Bookmarks("Filename").Range.Text

ActivePrinter = "PDF995"
SendKeys PDFFileName & "{ENTER}", False
Application.PrintOut FileName:="", Range:=wdPrintAllDocument, Item:= _
wdPrintDocumentContent, Copies:=1, Pages:="",
PageType:=wdPrintAllPages, _
Collate:=True, Background:=True, PrintToFile:=False
End Sub

When I run it, I'm still getting the print dialog box that asks for the File
Name that it is to be saved as.

Any guidance as to how I cab amend the code would be sincerely appreciated.
 
D

Doug Robbins - Word MVP

It would be a feature of PDF995 that you would need to modify.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top