Whats The Point Of PDF Creator?
Hi all,
This may be contentious but what the heck.
I posted a request in the Help forum to try to find out a definitive, robust solution to the problem of PDFCreator hanging when cClose is executed ie one which does not rely on putting "wait" statements all over your code and hoping. I have tried everything I could think of but to no avail. There seem to be many instances of other people reporting the same issue from several versions ago but the problem still doesnt appear to be solved in the latest version (0.9.5).
If the product cant be used without hanging and there is no clear solution, whats the point of continuing distributing new versions without first fixing that?
If this cant be solved does anyone know of an alternative free solution which will work with VB macros?
No problems with my code. PDFCreator doesn't hang and all works fine.
Best regards,
Frank
Option Explicit
Private Const MAX_PATH As Long = 260&
Private Declare Sub Sleep Lib "kernel32.dll" (ByVal dwMilliseconds As Long)
Private Declare Function GetShortPathName Lib "kernel32" Alias "GetShortPathNameA" ( _
ByVal lpszLongPath As String, ByVal lpszShortPath As String, ByVal cchBuffer As Long) As Long
Private Declare Function ShellExecute Lib "shell32.dll" Alias _
"ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation _
As String, ByVal lpFile As String, ByVal lpParameters _
As String, ByVal lpDirectory As String, ByVal nShowCmd _
As Long) As Long
Private PDFCreator1 As Object
Private ReadyState As Boolean, DefaultPrinter As String
Public Sub ToPDF()
Dim outName As String, path As String, outputFilename As String
If InStr(1, ActiveWorkbook.Name, ".", vbTextCompare) > 1 Then
outName = Mid(ActiveWorkbook.Name, 1, InStr(1, ActiveWorkbook.Name, ".", vbTextCompare) - 1)
Else
outName = ActiveWorkbook.Name
End If
Set PDFCreator1 = CreateObject(Class:="PDFCreator.clsPDFCreator")
With PDFCreator1
If .cStart("/NoProcessingAtStartup") = False Then
MsgBox "Can't initialize PDFCreator."
Exit Sub
End If
End With
With PDFCreator1
.cOption("UseAutosave") = 1
.cOption("UseAutosaveDirectory") = 1
.cOption("AutosaveDirectory") = ActiveWorkbook.path
.cOption("AutosaveFilename") = outName
.cOption("AutosaveFormat") = 0 ' 0 = PDF
.cClearCache
End With
Application.Sheets(1).PrintOut Copies:=1, ActivePrinter:="PDFCreator"
Do Until PDFCreator1.cCountOfPrintjobs = Application.Sheets.Count
DoEvents
Sleep 250
Loop
PDFCreator1.cPrinterStop = False
Do Until PDFCreator1.cCountOfPrintjobs = 0
DoEvents
Sleep 250
Loop
outputFilename = PDFCreator1.cOutputFilename
PDFCreator1.cClose
Sleep 1000
Set PDFCreator1 = Nothing
path = Space(MAX_PATH)
Call GetShortPathName(outputFilename, path, MAX_PATH)
Call ShellExecute(0, "Open", path, "", ActiveWorkbook.path, 1)
End Sub