Here's an example of BullZip PDF generation in VBA (Excel)
Posted: Wed May 02, 2007 11:14 pm
Here's an example of a BullZip PDF generation macro in VBA for Excel, if anyone's interested.
[code]
Sub PrintSheetAsPDFwithBullZip()
'must add a reference to BullZip
Dim myobject As New Bullzip.PDFPrinterSettings
Dim SavePath As String, FileName As String
SavePath = Environ("HOMEDRIVE") & Environ("HOMEPATH") & "\Desktop\"
FileName = InputBox("Save PDF to desktop as:", "Sheet '" & ActiveSheet.name & "' to PDF...", ActiveSheet.name)
If LCase(Right(FileName, 4)) <> ".pdf" Then FileName = FileName & ".pdf"
'see default settings in
'Environ("HOMEDRIVE") & Environ("APPDATA") & "\Bullzip\PDF Printer\settings.ini"
myobject.SetValue "output", SavePath & FileName
myobject.SetValue "showsettings", "never"
myobject.WriteSettings (True) 'writes the settings in a runonce.ini that it immediately deleted after being used.
'change to bullzip printer...
If InStr(ActivePrinter, "BullZip") = 0 Then
Dim storeprinter$, PrinterChanged As Boolean
PrinterChanged = True
storeprinter = ActivePrinter
ActivePrinter = GetFullNetworkPrinterName("BullZip")
End If
ActiveSheet.PrintOut
If PrinterChanged Then ActivePrinter = storeprinter
End Sub
'the following code is from http://www.erlandsendata.no/english/ind ... ngeprinter
Function GetFullNetworkPrinterName(strNetworkPrinterName As String) As String
' returns the full network printer name
' returns an empty string if the printer is not found
' e.g. GetFullNetworkPrinterName("HP LaserJet 8100 Series PCL")
' might return "HP LaserJet 8100 Series PCL on Ne04:"
Dim strCurrentPrinterName As String, strTempPrinterName As String, i As Long
strCurrentPrinterName = Application.ActivePrinter
i = 0
Do While i < 100
strTempPrinterName = strNetworkPrinterName & " on Ne" & Format(i, "00") & ":"
On Error Resume Next ' try to change to the network printer
Application.ActivePrinter = strTempPrinterName
On Error GoTo 0
If Application.ActivePrinter = strTempPrinterName Then
' the network printer was found
GetFullNetworkPrinterName = strTempPrinterName
i = 100 ' makes the loop end
End If
i = i + 1
Loop
' remove the line below if you want the function to change the active printer
Application.ActivePrinter = strCurrentPrinterName ' change back to the original printer
End Function
[/code]
[code]
Sub PrintSheetAsPDFwithBullZip()
'must add a reference to BullZip
Dim myobject As New Bullzip.PDFPrinterSettings
Dim SavePath As String, FileName As String
SavePath = Environ("HOMEDRIVE") & Environ("HOMEPATH") & "\Desktop\"
FileName = InputBox("Save PDF to desktop as:", "Sheet '" & ActiveSheet.name & "' to PDF...", ActiveSheet.name)
If LCase(Right(FileName, 4)) <> ".pdf" Then FileName = FileName & ".pdf"
'see default settings in
'Environ("HOMEDRIVE") & Environ("APPDATA") & "\Bullzip\PDF Printer\settings.ini"
myobject.SetValue "output", SavePath & FileName
myobject.SetValue "showsettings", "never"
myobject.WriteSettings (True) 'writes the settings in a runonce.ini that it immediately deleted after being used.
'change to bullzip printer...
If InStr(ActivePrinter, "BullZip") = 0 Then
Dim storeprinter$, PrinterChanged As Boolean
PrinterChanged = True
storeprinter = ActivePrinter
ActivePrinter = GetFullNetworkPrinterName("BullZip")
End If
ActiveSheet.PrintOut
If PrinterChanged Then ActivePrinter = storeprinter
End Sub
'the following code is from http://www.erlandsendata.no/english/ind ... ngeprinter
Function GetFullNetworkPrinterName(strNetworkPrinterName As String) As String
' returns the full network printer name
' returns an empty string if the printer is not found
' e.g. GetFullNetworkPrinterName("HP LaserJet 8100 Series PCL")
' might return "HP LaserJet 8100 Series PCL on Ne04:"
Dim strCurrentPrinterName As String, strTempPrinterName As String, i As Long
strCurrentPrinterName = Application.ActivePrinter
i = 0
Do While i < 100
strTempPrinterName = strNetworkPrinterName & " on Ne" & Format(i, "00") & ":"
On Error Resume Next ' try to change to the network printer
Application.ActivePrinter = strTempPrinterName
On Error GoTo 0
If Application.ActivePrinter = strTempPrinterName Then
' the network printer was found
GetFullNetworkPrinterName = strTempPrinterName
i = 100 ' makes the loop end
End If
i = i + 1
Loop
' remove the line below if you want the function to change the active printer
Application.ActivePrinter = strCurrentPrinterName ' change back to the original printer
End Function
[/code]