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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Convert an excel file to pdf

Status
Not open for further replies.

Taxidriver

Programmer
Jan 15, 2002
79
IT
How can I do that?
 
I'm using the code I found in another thread

' Define the postscript and .pdf file names.
Dim PSFileName As String
Dim PDFFileName As String
PSFileName = "C:\myPostScript.ps"
PDFFileName = "C:\myPDF.pdf"

' Print the Excel range to the postscript file
Dim Foglio1 As Worksheet
Set Foglio1 = ActiveSheet


Foglio1.PrintOut copies:=1, preview:=False, _
ActivePrinter:="Acrobat Distiller", printtofile:=True, collate:=True, _
prtofilename:=PSFileName

' Convert the postscript file to .pdf

Dim myPDF As PdfDistiller
Set myPDF = New PdfDistiller
myPDF.FileToPDF PSFileName, PDFFileName, ""

I expect my sheet to be converted in a pdf but it appears that nothing happens. please do help me
 
You didn't say you were trying to do this programmatically. My reply would have been a little more detailed, otherwise.

I don't program in VB, so my help won't be much... help.

But I'll try: do you need to check for a succesful print, prior to trying to use Distiller?

Try adding a loop between your printing code and your Distilling code. In that loop, you'll need a "DoEvents()" or whatever the proper VB code is to allow Windows to keep doing whatever else it is doing.

In that loop, you'll need to test that your print file was created, possibly by trying to open it with standard VB File I/O.

When you confirm that the postscript file was succesfully created, then you can move on to your Distiller code block.



Thomas D. Greer

Providing PostScript & PDF
Training, Development & Consulting
 
OK now I can see that the file is generaTED but I cannot open it,it says that it is damaged!
 
I've seen this type of problem when generating files dynamically, and then trying to pass that file onto another process. You have to wait for the system to release all application and OS locks on the file. Thus the loop to test to see if your app can open the file.

I'm glad it's working.



Thomas D. Greer

Providing PostScript & PDF
Training, Development & Consulting
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top