Update Page Number in cell for Print Area

engpe

New Member
Joined
Feb 29, 2012
Messages
1
Hello all,

I would like to be able to update the page number in a repeating print area and have a single printout command to produce a single pdf file. The print area is fixed and I know the number of pages (3). There is a cell where the user can input the first page number to be used.

Here is the code that I have been using.

Sub PrintPages()

Dim NumSheets As Double, FirstPageNum As Double, SheetNumOutput As Range

Set SheetNumOutput = myWorksheet.Range("I2")
NumSheets = 3
FirstPageNum = myWorksheet.Cells(11, 11) 'User inputs first page number.

For n = 1 To NumSheets
SheetNumOutput.Value = FirstPageNum + n - 1
myWorksheet.PrintOut n, n, 1, True
Next n

End Sub

The problem is that when I try to print to a pdf, I get separate printout for each page. I would like to have this functionality while printing to only one pdf file. This code works when I print to a regular printer, but not to a pdf creator.

Thanks,

Jeremy
 

Some videos you may like

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.

Watch MrExcel Video

Forum statistics

Threads
1,118,873
Messages
5,574,752
Members
412,617
Latest member
mlharris
Top