VBA Macro issue-excel spreadsheet to PDF with password encoding

mbanner

New Member
Joined
Jan 31, 2017
Messages
1
Good afternoon. I am hoping someone can help me out. I have a new job that requires me to run a VBA Macro. The macro is supposed to create a PDF document from an Excel Spreadsheet and encode it with a password. When I run the macro I get an "Run time error "429": ActiveX component can't create object." When I go to debug, the macro highlights the line
Set pdfjob = CreateObject("PDFCreator.clsPDFCreator").
I do have the newest version of PDF creator as well as PDF architect installed on my computer. I have no idea what this error requires I do.
I am copying all of the code below. I would appreciate any and all help. Thank You.


Sub PrintToPDF(StrR As String, StrEE As String, StrPass As String, StrMstPass As String)




Dim pdfjob As Object
Dim sPDFName As String
Dim sPDFPath As String
Dim sMasterPass As String
Dim sUserPass As String


'/// Change the output file name here! ///
sPDFName = StrR & "-" & StrEE
sPDFPath = "C:\Test\test"
sMasterPass = StrMstPass
sUserPass = StrPass

'Check if worksheet is empty and exit if so
If IsEmpty(ActiveSheet.UsedRange) Then Exit Sub


Set pdfjob = CreateObject("PDFCreator.clsPDFCreator")

With pdfjob
If .cStart("/NoProcessingAtStartup") = False Then
MsgBox "Can't initialize PDFCreator.", vbCritical + _
vbOKOnly, "PrtPDFCreator"
Exit Sub
End If
.cOption("UseAutosave") = 1
.cOption("UseAutosaveDirectory") = 1
.cOption("AutosaveDirectory") = sPDFPath
.cOption("AutosaveFilename") = sPDFName
.cOption("AutosaveFormat") = 0 ' 0 = PDF
'The following are required to set security of any kind
.cOption("PDFUseSecurity") = 1
.cOption("PDFOwnerPass") = 1
.cOption("PDFOwnerPasswordString") = sMasterPass


'To set individual security options
.cOption("PDFDisallowCopy") = 0
.cOption("PDFDisallowModifyContents") = 1
.cOption("PDFDisallowPrinting") = 0


'To force a user to enter a password before opening
.cOption("PDFUserPass") = 1
.cOption("PDFUserPasswordString") = sUserPass
'To change to High encryption
'.cOption("PDFHighEncryption") = 1
.cClearCache
End With


'Print the document to PDF
ActiveSheet.PrintOut copies:=1, ActivePrinter:="PDFCreator"


'Wait until the print job has entered the print queue
Do Until pdfjob.cCountOfPrintjobs = 1
DoEvents
Loop
pdfjob.cPrinterStop = False


'Wait until PDF creator is finished then release the objects
Do Until pdfjob.cCountOfPrintjobs = 0
DoEvents
Loop
pdfjob.cClose:

Set pdfjob = Nothing
End Sub
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN

Forum statistics

Threads
1,214,950
Messages
6,122,428
Members
449,083
Latest member
Ava19

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top