Private Const cKey As String = "HKEY_CURRENT_USER\"
Private Const cDestination As String = "HKEY_CURRENT_USER\Software\Zeon\DocuCom\PDF DRIVER\Destination\"
Private Const cGeneral As String = "HKEY_CURRENT_USER\Software\zeon\docucom\pdf driver\General\"
Private m_sActivePrinter As String
Public Sub PrintOut(Optional ForceIfExists As Boolean = False)
On Error GoTo PrintOut_Error
Application.ScreenUpdating = False
If PDFSetup Then
m_sActivePrinter = Excel.Application.ActivePrinter
Excel.Application.ActivePrinter = "DocuCom PDF Driver on LPT1:"
SetFileSaveLocation (Me.OutputPath)
Dim bPrintout As Boolean
If Dir(Me.OutputPath) = "" Then
bPrintout = True
Else
If Not ForceIfExists Then
If MsgBox("The file """ & Me.OutputPath & """ already exists, do you wish to overwrite it?", vbYesNo Or vbCritical, "PDF Printer") = vbYes Then
Kill Me.OutputPath
bPrintout = True
End If
Else
Kill Me.OutputPath
bPrintout = True
End If
End If
If bPrintout Then
Dim Sht As Excel.Worksheet
For Each Sht In Me.Worksheets
Sht.PrintOut
Next Sht
End If
End If
PrintOut_Exit:
On Error Resume Next
ResetPDFSettings
Excel.Application.ActivePrinter = m_sActivePrinter
Application.ScreenUpdating = True
Exit Sub
PrintOut_Error:
Select Case Err
Case Else
VBA.MsgBox "Error " & VBA.Err.Number & " (" & VBA.Err.Description & ") in procedure PrintOut of Class Module PDFPrinter"
End Select
mStatusBar.SetStatusBar False
Resume PrintOut_Exit
Resume
End Sub
Private Sub SetFileSaveLocation(outputFileLocation As String)
On Error GoTo SetFileSaveLocation_Error
With CreateObject("WScript.Shell")
.RegWrite cDestination & "PDFName", outputFileLocation, "REG_SZ"
.RegWrite cDestination & "NamingMode", "1", "REG_SZ"
.RegWrite cDestination & "FileExistRule", "2", "REG_SZ"
End With
SetFileSaveLocation_Exit:
On Error Resume Next
Exit Sub
SetFileSaveLocation_Error:
Select Case Err
Case Else
VBA.MsgBox "Error " & VBA.Err.Number & " (" & VBA.Err.Description & ") in procedure SetFileSaveLocation of Class Module PDFPrinter"
End Select
Resume SetFileSaveLocation_Exit
Resume
End Sub
Public Function PDFSetup() As Boolean
Dim bResult As Boolean
On Error GoTo PDFSetup_Error
With CreateObject("WScript.Shell")
.RegWrite cKey & cGeneral, ""
.RegWrite cKey & cGeneral & "bMSOFFICE", "1", "REG_SZ"
.RegWrite cKey & cGeneral & "WebViewing", "1", "REG_SZ"
.RegWrite cKey & cGeneral & "StandardPage", "3", "REG_SZ"
.RegWrite cKey & cGeneral & "bViewPDF", "0", "REG_SZ"
End With
bResult = True
PDFSetup_Exit:
On Error Resume Next
PDFSetup = bResult
Exit Function
PDFSetup_Error:
Select Case Err
Case Else
VBA.MsgBox "Error " & VBA.Err.Number & " (" & VBA.Err.Description & ") in procedure PDFSetup of Class Module PDFPrinter"
End Select
Resume PDFSetup_Exit
Resume
End Function
Private Sub ResetPDFSettings()
mDebug.PrintOut "PDFPrinter.ResetPDFSettings"
On Error GoTo ResetPDFSettings_Error
With CreateObject("WScript.Shell")
.RegDelete cDestination
.RegDelete cGeneral
End With
ResetPDFSettings_Exit:
On Error Resume Next
Exit Sub
ResetPDFSettings_Error:
Select Case Err
Case Else
VBA.MsgBox "Error " & VBA.Err.Number & " (" & VBA.Err.Description & ") in procedure ResetPDFSettings of Class Module PDFPrinter"
End Select
Resume ResetPDFSettings_Exit
Resume
End Sub