Convert PS File to PDF

AlexMach

New Member
Joined
Apr 6, 2009
Messages
17
Every day I create many Excel reports that I manually save as PDFs for
distribution to my stakeholders. I'd like to automate this process using a macro.
I've seen the following code online and have attempted to use it, but receive
an error in the Dim MyPDF line of code indicating that the user-defined type
is not defined.

I'm using Excel 2003 and Acrobat Distiller 8. I have no problem creating
PDFs manually


Code:
[COLOR=#273d49][FONT=Arial]Sub Create_PDF()<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>[/FONT][/COLOR]
[COLOR=#273d49][FONT=Arial]<o:p> </o:p>[/FONT][/COLOR]
[COLOR=#273d49][FONT=Arial]Dim tempPDFFileName As String<o:p></o:p>[/FONT][/COLOR]
[COLOR=#273d49][FONT=Arial]Dim tempPSFileName As String<o:p></o:p>[/FONT][/COLOR]
[COLOR=#273d49][FONT=Arial]Dim tempPDFRawFileName As String<o:p></o:p>[/FONT][/COLOR]
[COLOR=#273d49][FONT=Arial]Dim tempLogFileName As String<o:p></o:p>[/FONT][/COLOR]
[COLOR=#273d49][FONT=Arial]Dim x As Integer<o:p></o:p>[/FONT][/COLOR]
[COLOR=#273d49][FONT=Arial]Dim ws As Worksheet<o:p></o:p>[/FONT][/COLOR]
[COLOR=#273d49][FONT=Arial]Dim PDFPath As String<o:p></o:p>[/FONT][/COLOR]
[COLOR=#273d49][FONT=Arial]<o:p> </o:p>[/FONT][/COLOR]
[COLOR=#273d49][FONT=Arial]ThisWorkbook.Worksheets(3).Select<o:p></o:p>[/FONT][/COLOR]
[COLOR=#273d49][FONT=Arial]<o:p> </o:p>[/FONT][/COLOR]
[COLOR=#273d49][FONT=Arial]For x = 3 To ThisWorkbook.Worksheets.Count<o:p></o:p>[/FONT][/COLOR]
[COLOR=#273d49][FONT=Arial]        If Worksheets(x).Visible = xlSheetVisible Then Worksheets(x).Select (False)<o:p></o:p>[/FONT][/COLOR]
[COLOR=#273d49][FONT=Arial]Next x<o:p></o:p>[/FONT][/COLOR]
[COLOR=#273d49][FONT=Arial]<o:p> </o:p>[/FONT][/COLOR]
[COLOR=#273d49][FONT=Arial]PDFPath = ActiveWorkbook.Path & Application.PathSeparator<o:p></o:p>[/FONT][/COLOR]
[COLOR=#273d49][FONT=Arial]tempPDFRawFileName = PDFPath & Left(Format(Date, "mm.dd.yyyy") & " " & wsAgenda.Range("I2"), Len(Format(Date, "mm.dd.yyyy") & " " & wsAgenda.Range("I2")))<o:p></o:p>[/FONT][/COLOR]
[COLOR=#273d49][FONT=Arial]<o:p> </o:p>[/FONT][/COLOR]
[COLOR=#273d49][FONT=Arial]tempPSFileName = tempPDFRawFileName & ".ps"<o:p></o:p>[/FONT][/COLOR]
[COLOR=#273d49][FONT=Arial]tempPDFFileName = tempPDFRawFileName & ".pdf"<o:p></o:p>[/FONT][/COLOR]
[COLOR=#273d49][FONT=Arial]tempLogFileName = tempPDFRawFileName & ".log"<o:p></o:p>[/FONT][/COLOR]
[COLOR=#273d49][FONT=Arial]<o:p> </o:p>[/FONT][/COLOR]
[COLOR=#273d49][FONT=Arial]ActiveWindow.SelectedSheets.PrintOut copies:=1, preview:=False, ActivePrinter:="Adobe PDF", printtofile:=True, Collate:=True, prtofilename:=tempPSFileName<o:p></o:p>[/FONT][/COLOR]
[COLOR=#273d49][FONT=Arial]<o:p> </o:p>[/FONT][/COLOR]
[COLOR=#273d49][FONT=Arial]Dim myPDF As PdfDistiller '<==== ERROR HERE: User-defined type not defined
Set myPDF = New PdfDistiller
myPDF.FileToPDF PSFileName, PDFFileName, ""<o:p></o:p>[/FONT][/COLOR]
[COLOR=#273d49][FONT=Arial]<o:p> </o:p>[/FONT][/COLOR]
[SIZE=3][COLOR=#000000][FONT=Times New Roman]Kill tempPSFileName[COLOR=#273d49][FONT=Arial]<o:p></o:p>[/FONT][/COLOR][/FONT][/COLOR][/SIZE]
[FONT=Times New Roman][SIZE=3][COLOR=#000000]Kill tempLogFileName[/COLOR][/SIZE][/FONT]
<o:p>[FONT=Times New Roman][SIZE=3][COLOR=#000000] [/COLOR][/SIZE][/FONT]</o:p>
[FONT=Times New Roman][SIZE=3][COLOR=#000000]End Sud[/COLOR][/SIZE][/FONT]
<o:p></o:p>
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
Maybe define the library?

Dim myPDF As ACRODISTXLib.PdfDistiller
Set myPDF = New ACRODISTXLib.PdfDistiller
 
Upvote 0

Forum statistics

Threads
1,214,649
Messages
6,120,732
Members
448,987
Latest member
marion_davis

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top