View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Pete_UK Pete_UK is offline
external usenet poster
 
Posts: 8,856
Default VB routine to print to PDF?

Here's a snippet of code that I put together a few years ago to do a
similar thing:

my_file = ActiveCell.Value
If my_file < "" _
Then
'as long as it is not blank, open the file, change
'to the Adobe printer, and print the pdf file
ChDir (this_client)
Workbooks.Open Filename:=my_file
my_printer = Application.ActivePrinter
Application.ActivePrinter = "Adobe PDF on Ne02:"
ActiveWindow.SelectedSheets.PrintOut Copies:=1, _
ActivePrinter:="Adobe PDF on Ne02:", Collate:=True
'switch back to installed printer driver
Application.ActivePrinter = my_printer
ActiveWorkbook.Close
ChDir ("..")
Else
'if the filename is blank, then don't check any more
j = num_users
End If

Excel files were stored in sub-directories under the name of the
client, and were written to a sheet in the master file such that each
filename for a particular client was in the same column. A loop cycled
through each client and then through each filename from the sheet, so
my_file was opened in sequence and a .pdf file of the same name was
written to the same sub-folder and then my_file was closed in
readiness for the next one. You might need to change Ne02 (twice) to
Ne01 to suit your requirements.

This was using Adobe Acrobat v7, but you might be able to adapt it to
suit your circumstances.

Hope this helps.

Pete


On Mar 14, 1:28*am, fedude wrote:
* I'm trying to write a routine that will print a pdf page. * I need to make
this a routine because I have to loop through a large set of data and print a
pdf page for each row of the data.

My typical method for writing a routine is to record a macro and then modify
the module I created. * Unfortunately, when I print to pdf using acrobat
distiller, the macro does not record all the steps. * In particular is does
not collect the filename or location. * Here is the macro I created when I
recorded my keystrokes:

Sub pdfPrint()
* * ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
End Sub

I need to specify the filename and location in the macro (different for each
row). *
Maybe I should be using another tool for creating the pdf files? *Any help
would be appreciated.

Ecxel 2003/Acrobat Distiller 5