Here is the code that I've been trying to use - perhaps you can tell me where my attempted adaptation has gone off into the ethernet. As I mentioned earlier - code in your userform works very well, its my adapted code here that has to be single-stepped through to get an output file.
It almost becomes a curiousity thing now - since we may have decided to go with a .html file output of the one worksheet in question. But I'm always ready to learn something new.
Thank you
Option Explicit
Private Declare Sub Sleep Lib "kernel32.dll" (ByVal dwMilliseconds As Long)
' Add a reference to PDFCreator
'notice that I am not using WithEvents now. Creates an error
'outside of a class module anyhow.
'Private WithEvents PDFCreator1 As PDFCreator.clsPDFCreator
Private PDFCreator1 As Object
Private ReadyState As Boolean, DefaultPrinter As String
Private pdfStarted As Boolean
Sub PrintToPDFCreator()
'This is the main routine that would be called when
'I need to create a JPEG file of the active sheet
'
'Single step (F8) through the code and it works,
'let it just execute and no error is generated, but neither is the output file
'
Dim outName As String, i As Long
If Not pdfStarted Then
StartPDFPrinter
End If
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
'
'only need to output the current Active sheet, never the entire workbook
'
Sleep 1000
With PDFCreator1
.cOption("UseAutosave") = 1
.cOption("UseAutosaveDirectory") = 1
.cOption("AutosaveDirectory") = ActiveWorkbook.Path
Debug.Print outName & "-" & ActiveSheet.Name
.cOption("AutosaveFilename") = outName & "-" & ActiveSheet.Name
'.cOption("AutosaveFormat") = 0 ' 0 = PDF
'.cOption("AutosaveFormat") = 1 ' 1 = PNG
.cOption("AutosaveFormat") = 2 ' 2 = JPEG (.jpg)
.cClearCache
End With
ActiveSheet.PrintOut Copies:=1, ActivePrinter:="PDFCreator"
Sleep 1000
Do Until PDFCreator1.cCountOfPrintjobs = 1
DoEvents
Sleep 1000
Loop
Sleep 1000
PDFCreator1.cPrinterStop = False
ClosePDFPrinter
End Sub
Private Sub PDFCreator1_eError()
AddStatus "ERROR [" & PDFCreator1.cErrorDetail("Number") & "]: " & _
PDFCreator1.cErrorDetail("Description")
End Sub
Private Sub PDFCreator1_eReady()
AddStatus "File'" & PDFCreator1.cOutputFilename & "' was saved."
PDFCreator1.cPrinterStop = True
End Sub
Sub StartPDFPrinter()
If Len(ActiveWorkbook.Path) = 0 Then
MsgBox "Please save the document first!", vbExclamation
End
End If
Set PDFCreator1 = New clsPDFCreator
With PDFCreator1
If .cStart("/NoProcessingAtStartup") = False Then
AddStatus "Can't initialize PDFCreator."
Exit Sub
End If
End With
AddStatus "PDFCreator initialized."
pdfStarted = True
End Sub
Private Sub AddStatus(Str1 As String)
Sheet1.Range("A" & Rows.Count).End(xlUp).Offset(1, 0) = Now() & ":" & Str1
End Sub
Private Sub ClosePDFPrinter()
PDFCreator1.cClose
Set PDFCreator1 = Nothing
Sleep 250
DoEvents
pdfStarted = False
AddStatus "PDFCreator Closed"
End Sub