erprasannaa
New Member
- Joined
- Feb 13, 2013
- Messages
- 2
Dear Friends
I try to convert Normal pdf into password protected PDF through Excel VBA with the PDFCreator Printer.
while i run the code, it display Runtime error 462.
Please help to solve.
Full Code As Below.
I try to convert Normal pdf into password protected PDF through Excel VBA with the PDFCreator Printer.
while i run the code, it display Runtime error 462.
Please help to solve.
Full Code As Below.
Code:
Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
'ABOVE DELARTION USED TO DELAY THE WORKAROUND
'#####################################################################################################
Sub Rename_All3()
zProg = "C:\Program Files\Adobe\Reader 10.0\Reader\AcroRd32.exe"
Dim LastRow As Long, Rw As Long
'#######################################################################################################
'below set of variable declaration for pdf crator print job
Dim pdfjob As Object
'Dim pdfjob As PDFCreator.clsPDFCreator
Dim sPDFName As String
Dim sPDFPath As String
Dim sMasterPass As String
Dim sUserPass As String
'#######################################################################################################
LastRow = Cells(Rows.Count, "A").End(xlUp).Row 'Excel Coloumn "A" for Original Filename
LastRow = Cells(Rows.Count, "B").End(xlUp).Row 'Excel Coloumn "B" for Required Output file path
LastRow = Cells(Rows.Count, "C").End(xlUp).Row 'Excel Coloumn "A" for Required output file Name
LastRow = Cells(Rows.Count, "D").End(xlUp).Row 'Excel Coloumn "A" for Master Password string
LastRow = Cells(Rows.Count, "E").End(xlUp).Row 'Excel Coloumn "A" for User Password string
For Rw = 1 To LastRow
zFile = Cells(Rw, "A").Value
sPDFName = Cells(Rw, "C").Value
sPDFPath = Cells(Rw, "B").Value
sMasterPass = Cells(Rw, "D").Value
sUserPass = Cells(Rw, "E").Value
'#######################################################################################################
zCommand = zProg & " /n /h /t " & Chr(34) & zFile & Chr(34) & " " & zPrinter
Debug.Print zCommand
Shell (zCommand)
'End If 'end of test for pdf file type
'above is the end of one document sent to system default printer from excel file
'#####################################################################################################
Set pdfjob = CreateObject("PDFCreator.clsPDFCreator")
Sleep 1000
With pdfjob
If .cStart("/NoProcessingAtStartup") = False Then
Shell "taskkill /f /im PDFCreator.exe", vbHide
' 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") = 0
.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
Sleep 5000
Do Until pdfjob.cCountOfPrintjobs = 1
DoEvents
Loop
pdfjob.cPrinterStop = False
Do Until pdfjob.cCountOfPrintjobs = 0
DoEvents
Loop
Sleep 1000
'i = i + 1
'Application.StatusBar = i & " -" & sPDFName & " Printed at the path " & sPDFPath
pdfjob.cClose
Application.ScreenUpdating = True
End With
'#####################################################################################################
Next 'process next file in list
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
If IsError(optprice) Or IsError(stk) Or IsError(tme) Or IsError(r) Or IsError(exe) Then
MsgBox "error deducted", vbInformation, "Rename confirmation"
End If
'#####################################################################################################
MsgBox "Files Printed", vbInformation, "Rename confirmation"
Application.StatusBar = "Finished"
End Sub