Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Generating pdf from Excel VBA

Status
Not open for further replies.

sabascal

IS-IT--Management
Aug 20, 2002
85
GB
Guys quick question -

-I have a Acrobat Writer installed.
-I have a print area called "PrintArea1" in a Excel workbook.
-I am runing 5 different scenarios, and the content of PrintArea1 chances from 1 scen to the other.
-I have a macro that makes that scenarios run (1, 2, 3,...5).

I would like to modify my macro to print before changing scenario, PrintArea1, in a pdf document.

Either: 1 pdf file per scenario OR 1! pdf for the 5 scenarios.

Any hints on that?
I tried to recorded a macro. But it's not recording how do i give a name to the pdf file.

Many thanks
Seb

 
Don't know if applicable for PDFWriter, but the PrintOut method have 2 arguments related to your issue:
expression.PrintOut(From, To, Copies, Preview, ActivePrinter, PrintToFile, Collate, PrToFileName)



Hope This Help
PH.
 
Answer
========================
Sub pdfConverter()

Dim PSFileName As String, PDFFileName As String, DistillerCall As String
Dim ReturnValue As Variant

'Define the path and filenames (can get the names from a cell, and add the path & extension):
PSFileName = "C:\test.PS"
PDFFileName = "C:\test.PDF"

'If the files already exist, delete them:
If Dir(PSFileName) <> &quot;&quot; Then Kill (PSFileName)
If Dir(PDFFileName) <> &quot;&quot; Then Kill (PDFFileName)

'The Sendkeys characters are the full path and filename, followed by the &quot;Enter&quot; key.
' These are buffered until the &quot;print to file&quot; screen appears:

SendKeys PSFileName & &quot;{ENTER}&quot;, False
ActiveSheet.PrintOut , PrintToFile:=True

'Add double quotes around the PS filename and PDF filename:
PSFileName = Chr(34) & PSFileName & Chr(34)
PDFFileName = Chr(34) & PDFFileName & Chr(34)
DistillerCall = &quot;D:\Program Files\Adobe\Acrobat 6.0\Distillr\Acrodist.exe&quot; & &quot; /n /q /o&quot; & PDFFileName & &quot; &quot; & PSFileName

'Call the Acrobat Distiller to distill the PS file. ReturnValue is zero
'if the application doesn't open correctly:

ReturnValue = Shell(DistillerCall, vbNormalFocus)
If ReturnValue = 0 Then MsgBox &quot;Creation of &quot; & PDFFileName & &quot;failed.&quot;

End Sub
 
I know I'm Digging up bones resurecting this old post but I have the same question as that origionally posed by sabascal, how do i give the pdf a name? I am a fairly novice code writer so without a help file or object browser for the adobe pdf writer or distiller i dont know how to attack the problem from that end, the sub above works just fine in excel, my problem is that I am trying to print to a PDF from Autodesk Inventor. I can get to where I want to be through the print manager of the program right up untill it asks for a name which i want entered programatically, so what is the simple way to just enter a name in the filename field? sendkeys wont work because of some focus issue or programatic thing or something, either way i cant get it to work, any other ideas?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top