XL-Dennis
Well-known Member
- Joined
- Jul 27, 2002
- Messages
- 1,920
Hi Board,
I hade a problem with saving created PDF-files to the activeworkbooks folder.
Finally I could solve it myself

For thos who´s interested here is the final solution (need to add a check if activeworkbook is saved or not):<PRE><FONT color=blue>Sub</FONT>Convert_XLS_PDF()<FONT color=blue>Dim</FONT>stFileName<FONT color=blue> As</FONT><FONT color=blue> String</FONT><FONT color=blue>Dim</FONT>stFilePath<FONT color=blue> As</FONT><FONT color=blue> String</FONT><FONT color=blue>Dim</FONT>stActivePath<FONT color=blue> As</FONT><FONT color=blue> String</FONT><FONT color=blue>Dim</FONT>stActivePrinter<FONT color=blue> As</FONT><FONT color=blue> String</FONT><FONT color=blue>Dim</FONT>stTitle<FONT color=blue> As</FONT><FONT color=blue> String</FONT><FONT color=blue>Dim</FONT>objDistiller<FONT color=blue> As</FONT><FONT color=blue> New</FONT>ACRODISTXLib.PdfDistiller
stTitle = "Konvertera Excel-filer till PDF-dokument"
stFileName = ActiveWorkbook.Name
stFileName = Left(stFileName, Len(stFileName) - 3)
stFilePath = ActiveWorkbook.Path
stActivePrinter = Application.ActivePrinter<FONT color=blue>On Error</FONT><FONT color=blue>GoTo</FONT> Errorhandling
Application.ActivePrinter = "Acrobat Distiller på Ne01:"
ActiveSheet.PrintOut PrToFilename:=stFilePath & "" & stFileName & "ps"
objDistiller.FileToPDF stFilePath & "" & stFileName & "ps", stFilePath & "" & stFileName & "pdf", ""
Kill stFilePath & "" & stFileName & "ps"
Application.ActivePrinter = stActivePrinter<FONT color=blue>Set</FONT>objDistiller =<FONT color=blue> Nothing</FONT><FONT color=blue>Exit Sub</FONT>
Errorhandling:<FONT color=blue>If</FONT>Err.Number = 1004 Then
MsgBox "Antingen avbröts utskriften eller så inträffade ett allvarligt fel.", vbInformation, stTitle<FONT color=blue>Else</FONT>
MsgBox "Acrobat Distiller är ej installerad.", vbInformation, stTitle<FONT color=blue>End If</FONT><FONT color=blue>Exit Sub</FONT><FONT color=blue>End Sub</FONT></PRE>
Kind regards,
Dennis
This message was edited by XL-Dennis on 2002-08-22 03:00
I hade a problem with saving created PDF-files to the activeworkbooks folder.
Finally I could solve it myself
For thos who´s interested here is the final solution (need to add a check if activeworkbook is saved or not):<PRE><FONT color=blue>Sub</FONT>Convert_XLS_PDF()<FONT color=blue>Dim</FONT>stFileName<FONT color=blue> As</FONT><FONT color=blue> String</FONT><FONT color=blue>Dim</FONT>stFilePath<FONT color=blue> As</FONT><FONT color=blue> String</FONT><FONT color=blue>Dim</FONT>stActivePath<FONT color=blue> As</FONT><FONT color=blue> String</FONT><FONT color=blue>Dim</FONT>stActivePrinter<FONT color=blue> As</FONT><FONT color=blue> String</FONT><FONT color=blue>Dim</FONT>stTitle<FONT color=blue> As</FONT><FONT color=blue> String</FONT><FONT color=blue>Dim</FONT>objDistiller<FONT color=blue> As</FONT><FONT color=blue> New</FONT>ACRODISTXLib.PdfDistiller
stTitle = "Konvertera Excel-filer till PDF-dokument"
stFileName = ActiveWorkbook.Name
stFileName = Left(stFileName, Len(stFileName) - 3)
stFilePath = ActiveWorkbook.Path
stActivePrinter = Application.ActivePrinter<FONT color=blue>On Error</FONT><FONT color=blue>GoTo</FONT> Errorhandling
Application.ActivePrinter = "Acrobat Distiller på Ne01:"
ActiveSheet.PrintOut PrToFilename:=stFilePath & "" & stFileName & "ps"
objDistiller.FileToPDF stFilePath & "" & stFileName & "ps", stFilePath & "" & stFileName & "pdf", ""
Kill stFilePath & "" & stFileName & "ps"
Application.ActivePrinter = stActivePrinter<FONT color=blue>Set</FONT>objDistiller =<FONT color=blue> Nothing</FONT><FONT color=blue>Exit Sub</FONT>
Errorhandling:<FONT color=blue>If</FONT>Err.Number = 1004 Then
MsgBox "Antingen avbröts utskriften eller så inträffade ett allvarligt fel.", vbInformation, stTitle<FONT color=blue>Else</FONT>
MsgBox "Acrobat Distiller är ej installerad.", vbInformation, stTitle<FONT color=blue>End If</FONT><FONT color=blue>Exit Sub</FONT><FONT color=blue>End Sub</FONT></PRE>
Kind regards,
Dennis
This message was edited by XL-Dennis on 2002-08-22 03:00