Easy (?) printing question

S

Stevebo

I can't seem to get Word VBA to print out anything except my entire
document, and then, only to a printer.

Ideally, I'd like to print a .pdf of say, pages 1, 3, 8, 22, 23, 27

The variable Disp2 is set to "1, 3, 8, 22, 23, 27" (changes depending
on document)

But the following code prints the entire document:

'To file
ActiveDocument.ActiveWindow.PrintOut _
PrintTofile:=True, OutputFileName:=fn, Range:=wdPrintRangeOfPages,
Pages:=Disp2

'To printer
ActiveDocument.ActiveWindow.PrintOut _
Range:=wdPrintRangeOfPages, Pages:=Disp2

What am I missing?
Thanks,
Steve
 
D

Doug Robbins - Word MVP

If you want to create a .pdf file, you must have a .pdf printer installed.

The following code creates a .pdf file containing the nominated pages, with
the name of the document (if in the printer properties of the Adobe PDF
printer the "Prompt for Adobe PDF filename" option is unchecked:

Dim Disp As String
Disp = "p1, p3, p8, p22, p23, p27"
With Dialogs(wdDialogFilePrintSetup)
.Printer = "Adobe PDF"
.DoNotSetAsSysDefault = True
.Execute
End With

ActiveDocument.PrintOut Range:=wdPrintRangeOfPages, Pages:=Disp


--
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
 
G

Gordon Bentley-Mix

Steve,

Further to Doug's post: Although _you_ might think of PDF as a "file", Word
considers it a "printer". As evidence of this you will note that "Adobe PDF"
(if installed) is listed as a printer in the Print dialog.

In addition, although Doug correctly indicated that you should use
".DoNotSetAsSysDefault = True" to prevent Adobe PDF from being set as the
default printer, you may want to take a closer look at this; changing the
selected printer may be "sticky", so this selection may remain until Word is
restarted. Consequently, you may need to record what the currently selected
printer is prior to printing the document to PDF and set it back after the
event.
--
Cheers!
Gordon

Uninvited email contact will be marked as SPAM and ignored. Please post all
follow-ups to the newsgroup.
 
S

Stevebo

Thank you Doug! I really appreciate this.

One question however. Can you point me to a reference that discusses
printing of pages and sections? My VBA scans the document for certain
items, records the page they're on using wdActiveEndPageNumber, and
tries to 'print' out those pages. Unfortunately, in a 100 page
document that's made up of 5 sections of 20 pages, page 100 is
undefined if I use Disp = "p100".

I'm experimenting with wdActiveEndAdjustedPageNumber and
wdActiveEndSectionNumber, but don't know the syntax for setting Disp.

Any help appreciated.
Steve
 
D

Doug Robbins - Word MVP

You will need to make use of the wdActiveEndSectionNumber attributed of the
Selection.Information property in addition to the wdActiveEndPageNumber to
construct a string that contains the page and the section number for each
page - p#s#

--
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

Thank you Doug! I really appreciate this.

One question however. Can you point me to a reference that discusses
printing of pages and sections? My VBA scans the document for certain
items, records the page they're on using wdActiveEndPageNumber, and
tries to 'print' out those pages. Unfortunately, in a 100 page
document that's made up of 5 sections of 20 pages, page 100 is
undefined if I use Disp = "p100".

I'm experimenting with wdActiveEndAdjustedPageNumber and
wdActiveEndSectionNumber, but don't know the syntax for setting Disp.

Any help appreciated.
Steve
 

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