Excel 2010 64-bit and VBA
Posted: Mon Jan 17, 2011 11:43 pm
I have been trying to convert the example code for excel vba to work in the 64-bit environment. I have gotten past the .GetPrinterName property not working for Bullzip.PDFSettings. I was able to get it from Bullzip.PDFUtil.defaultprintername. I cannot get past getting the Bullzip.PDFSettings.printername . The code below will give an run-time error "-2146233088 (80131500)": This PrinterName property must be set before calling the GetFileSettingsFilePath Method.
Function PrintSheetAsPDF(file_name As String, merge_file_name As String, doc_title As String, author As String, save_path As String, subject_name As String, keywords As String)
Dim obj_printer_settings As Object
Dim obj_printer_util As Object
Dim current_printer As String
Dim progid As String
Dim utilprogid As String
Dim printername As String
Dim full_printer_name As String
Dim New64bitOS As Boolean
New64bitOS = False
#If VBA7 Then
' code running the new vba7 editor
#If Win64 Then
' code is running in 64-bit version of Microsoft office
New64bitOS = True
#End If
#End If
Rem -- Set the program id of the automation object.
If New64bitOS Then
progid = "Bullzip.PdfSettings"
utilprogid = "Bullzip.PDFUtil"
Set obj_printer_util = CreateObject(utilprogid)
Rem -- Create the object to control the printer settings
Set obj_printer_settings = CreateObject(progid)
Rem -- Get default printer name
printername = obj_printer_util.defaultprintername
Else
progid = "Bullzip.PDFPrinterSettings"
utilprogid = ""
Rem -- Create the object to control the printer settings
Set obj_printer_settings = CreateObject(progid)
Rem -- Get default printer name
printername = obj_printer_settings.GetPrinterName
End If
Rem -- Get the full name of the printer
full_printer_name = FindPrinter(printername)
full_printer_name = GetFullNetworkPrinterName(full_printer_name)
Rem -- Prompt the user for a file name
' file_name = InputBox("Save PDF to desktop as:", "Sheet '" & _
' ActiveSheet.Name & "' to PDF...", ActiveSheet.Name)
Rem -- Abort the process if the user cancels the dialog
If file_name = "" Then Exit Function
Rem -- Make sure that the file name ends with .pdf
If LCase(Right(file_name, 4)) <> ".pdf" Then
file_name = file_name & ".pdf"
End If
Rem -- Write the settings to the printer
Rem -- Settings are written to the runonce.ini
Rem -- This file is deleted immediately after being used.
With obj_printer_settings
.SetValue "output", save_path & file_name
.SetValue "showsettings", "never"
.SetValue "ConfirmOverwrite", "no"
.SetValue "ShowPDF", "no"
.SetValue "Target", "prepress"
.SetValue "Author", author
.SetValue "Title", doc_title
.SetValue "Subject", subject_name
.SetValue "Keywords", keywords
.SetValue "UseThumbs", "no"
.SetValue "AutoRotatePages", "all"
.SetValue "Linearize", "yes"
.SetValue "Res", "3600"
If merge_file_name <> "" Then
.SetValue "MergeFile", save_path & merge_file_name
.SetValue "MergePosition", "bottom"
End If
.WriteSettings True
End With
Rem -- Change to PDF printer
current_printer = ActivePrinter
ActivePrinter = full_printer_name
Rem -- Print the active work sheet
ActiveSheet.PrintOut
Rem -- Restore the printer selection
ActivePrinter = current_printer
End Function
Function PrintSheetAsPDF(file_name As String, merge_file_name As String, doc_title As String, author As String, save_path As String, subject_name As String, keywords As String)
Dim obj_printer_settings As Object
Dim obj_printer_util As Object
Dim current_printer As String
Dim progid As String
Dim utilprogid As String
Dim printername As String
Dim full_printer_name As String
Dim New64bitOS As Boolean
New64bitOS = False
#If VBA7 Then
' code running the new vba7 editor
#If Win64 Then
' code is running in 64-bit version of Microsoft office
New64bitOS = True
#End If
#End If
Rem -- Set the program id of the automation object.
If New64bitOS Then
progid = "Bullzip.PdfSettings"
utilprogid = "Bullzip.PDFUtil"
Set obj_printer_util = CreateObject(utilprogid)
Rem -- Create the object to control the printer settings
Set obj_printer_settings = CreateObject(progid)
Rem -- Get default printer name
printername = obj_printer_util.defaultprintername
Else
progid = "Bullzip.PDFPrinterSettings"
utilprogid = ""
Rem -- Create the object to control the printer settings
Set obj_printer_settings = CreateObject(progid)
Rem -- Get default printer name
printername = obj_printer_settings.GetPrinterName
End If
Rem -- Get the full name of the printer
full_printer_name = FindPrinter(printername)
full_printer_name = GetFullNetworkPrinterName(full_printer_name)
Rem -- Prompt the user for a file name
' file_name = InputBox("Save PDF to desktop as:", "Sheet '" & _
' ActiveSheet.Name & "' to PDF...", ActiveSheet.Name)
Rem -- Abort the process if the user cancels the dialog
If file_name = "" Then Exit Function
Rem -- Make sure that the file name ends with .pdf
If LCase(Right(file_name, 4)) <> ".pdf" Then
file_name = file_name & ".pdf"
End If
Rem -- Write the settings to the printer
Rem -- Settings are written to the runonce.ini
Rem -- This file is deleted immediately after being used.
With obj_printer_settings
.SetValue "output", save_path & file_name
.SetValue "showsettings", "never"
.SetValue "ConfirmOverwrite", "no"
.SetValue "ShowPDF", "no"
.SetValue "Target", "prepress"
.SetValue "Author", author
.SetValue "Title", doc_title
.SetValue "Subject", subject_name
.SetValue "Keywords", keywords
.SetValue "UseThumbs", "no"
.SetValue "AutoRotatePages", "all"
.SetValue "Linearize", "yes"
.SetValue "Res", "3600"
If merge_file_name <> "" Then
.SetValue "MergeFile", save_path & merge_file_name
.SetValue "MergePosition", "bottom"
End If
.WriteSettings True
End With
Rem -- Change to PDF printer
current_printer = ActivePrinter
ActivePrinter = full_printer_name
Rem -- Print the active work sheet
ActiveSheet.PrintOut
Rem -- Restore the printer selection
ActivePrinter = current_printer
End Function