Results 1 to 9 of 9

I cannot control PDFtk through VBA code

Threaded View

  1. #5
    Registered User
    Join Date
    12-20-2023
    Location
    bucharest
    MS-Off Ver
    16
    Posts
    4

    Re: I cannot control PDFtk through VBA code

    see here the VBA code tested; many thanks
    Sub Protectpdf()
        Dim PDFtkPath As String
        Dim InputFilePath As String
        Dim OutputFilePath As String
        Dim Password As String
        Dim ShellCmd As String
    
        ' Path to the PDFtk executable
      PDFtkPath = "C:\Program Files (x86)\PDFtk\bin\Pdftkxp.exe"
        
        ' Path to the input PDF file
        InputFilePath = "D:\Test\input.pdf"
        ' Path to the output PDF file (password protected)
        OutputFilePath = "D:\Test\output.pdf"
        
        
        ' Password for the PDF file
        Password = "090046"
    
        ' Assemble the command to password protect the PDF using PDFtk
        
        ShellCmd = PDFtkPath & " " & InputFilePath & " output " & OutputFilePath & " user_pw " & Password
        
        'alternative syntax not working:
        'ShellCmd = Chr(34) & PDFtkPath & Chr(34) & " " & Chr(34) & InputFilePath & Chr(34) & " output " & Chr(34) & OutputFilePath & Chr(34) & " user_pw " & Password
            
        'or, another one not working:
        'ShellCmd = PDFtkPath & " """ & InputFilePath & """ output """ & OutputFilePath & """ user_pw " & Password
    
        
        ' Use the Shell function to execute the PDFtk command
        Shell ShellCmd, vbHide
    
        MsgBox "PDF file has been password protected and saved to " & OutputFilePath
    End Sub
    Last edited by 6StringJazzer; 12-20-2023 at 11:56 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. using PDFTK to print pdf and append existing files
    By prabhakaranpd in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-08-2023, 10:28 AM
  2. Exit Userform control and revert to previous control value code - ESC key equiv
    By ddeluca in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-31-2020, 08:18 PM
  3. PDFtk, overlay PDF files (multibackground), Excel VBA Macro
    By apoliticalpoindexter in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-10-2018, 10:14 AM
  4. Using Pdftk to merge various files
    By fobioha in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 12-01-2017, 09:21 AM
  5. fix error with PDFtk?
    By chien_bap in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-16-2016, 02:35 AM
  6. Import PDFTK data dump into Excel
    By Brawnystaff in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-17-2015, 10:27 AM
  7. [SOLVED] VBA Code to have a repeating form control /Active X control (List box) in every row
    By Ehezve in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-28-2013, 08:55 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1