Run-Time error '462':

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.
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
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.

Forum statistics

Threads
1,223,270
Messages
6,171,103
Members
452,379
Latest member
IainTru

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