+ Reply to Thread
Results 1 to 9 of 9

I cannot control PDFtk through VBA code

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

    Question I cannot control PDFtk through VBA code

    I'm using PDFtk pro with intention to password protect some pdf files with VBA code.
    When I'm using Shell command, the arguments are not interpreted by the command.
    syntax I'm using:



    ShellCmd = PDFtkPath & " " & InputFilePath & " output " & OutputFilePath & " user_pw " & Password

    ' Use the Shell function to execute the PDFtk command
    Shell ShellCmd, vbHide

    the PTFtk application starts, but the Shell arguments are ignored and the command do not return a password protected pdf
    Do you know the reasons?

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2502
    Posts
    26,969

    Re: I cannot control PDFtk through VBA code

    I am using PDFtk Server but not for passwords, so I haven't done this exact thing. But your code looks correct. How about the data? If you have spaces in your paths this won't work. You need to quote the strings. It's easy to try this change:

    ShellCmd = PDFtkPath & " """ & InputFilePath & """ output """ & OutputFilePath & """ user_pw " & Password
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

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

    Re: I cannot control PDFtk through VBA code

    just tried. still not working. thank you

  4. #4
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2502
    Posts
    26,969

    Re: I cannot control PDFtk through VBA code

    Can you either

    Attach the file (see yellow banner at the top of the page)

    or

    show all your code

  5. #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
    Please Login or Register  to view this content.
    Last edited by 6StringJazzer; 12-20-2023 at 11:56 PM.

  6. #6
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2502
    Posts
    26,969

    Re: I cannot control PDFtk through VBA code

    Administrative Note:

    Welcome to the forum.

    We would very much like to help you with your query, however we recommend that you include code tags around your code.

    Please take a moment to add the tags. Posting code between [code]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/code] tags makes your code much easier to read and copy for testing, and it also maintains VBA formatting.

    Please see Forum Guideline #2 about code tags and adjust accordingly.

    I did it for you because you are a new member.

  7. #7
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2502
    Posts
    26,969

    Re: I cannot control PDFtk through VBA code

    You are calling the Windows version of the app. You need to use the Server for line commands. Change your line of code to this:

    Please Login or Register  to view this content.
    You still need to use my version of the shell call with the quotes if you have any spaces in the file path. I would recommend you do it anyway.

    Please Login or Register  to view this content.

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

    Re: I cannot control PDFtk through VBA code

    it WORKS !! thanks a lot !!

    I have puted PDFtkPath = "C:\Program Files (x86)\PDFtk\bin\pdftk.exe", but not server (acc the folder created by the install routine) and your shellcmd syntax.

    So, it was solved!

  9. #9
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2502
    Posts
    26,969

    Re: I cannot control PDFtk through VBA code

    Glad to hear it was solved. I gave you the PDFtk path as it is installed on my machine. Maybe yours is different.

    If your question has been answered please mark your thread as "Solved" so that members will know by looking at the thread title that your problem is solved. Go to the menu immediately above your first post to the thread and click on Thread Tools. From the dropdown menu select "Mark this thread as solved..."

    If a member helped you solve your problem, consider adding to their reputation by clicking addreputationiconsmall.jpg below their name.

+ Reply to Thread

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