Dear Team,

I have multiple PDFs named after their respective employee IDs. I need to apply a unique password to each PDF, and the same is captured in an Excel sheet.

I need a macro that will assign the specified unique password to each PDF.

From United Kingdom
Acknowledge(0)
Amend(0)

To set different passwords for each PDF file based on employee IDs using an Excel macro, follow these steps:

Step 1: Ensure that you have the list of employee IDs and their corresponding passwords in an Excel sheet, with one column for employee IDs and another for passwords.

Step 2: Open Excel and press "Alt + F11" to open the Visual Basic for Applications (VBA) editor.

Step 3: Go to "Insert" and then "Module" to create a new module for the macro.

Step 4: Copy and paste the following VBA code into the module:

```vba
Sub SetPDFPasswords()
Dim MyPath As String
Dim MyFile As String
Dim MyPassword As String
Dim MyID As String

MyPath = "C:\Your\PDF\Folder\" 'Specify the path where your PDFs are located

For Each cell In Sheets("Sheet1").Range("A2:A" & Sheets("Sheet1").Cells(Rows.Count, 1).End(xlUp).Row)
MyID = cell.Value
MyPassword = cell.Offset(0, 1).Value
MyFile = MyPath & MyID & ".pdf"

'Use a PDF library or tool to set the password for each PDF file
'Example code to set password using Adobe Acrobat:
'Shell "cmd /c """"C:\Program Files (x86)\Adobe\Acrobat DC\Acrobat\acrobat.exe"" /N /T " & MyFile & " """" """" "" & MyPassword & """" """"", vbNormalFocus

Next cell
End Sub
```

Step 5: Modify the code to include the correct path to your PDF folder and adjust any PDF library-specific commands if needed.

Step 6: Save the macro and close the VBA editor.

Step 7: Go back to Excel, run the macro by pressing "Alt + F8," selecting "SetPDFPasswords," and clicking "Run."

This macro will iterate through each employee ID and password in your Excel sheet, locate the corresponding PDF file, and set the specified password for each PDF. Make sure to test the macro on a sample set of PDFs before applying it to all files.

From India, Gurugram
Acknowledge(0)
Amend(0)

Join Our Community and get connected with the right people who can help. Our AI-powered platform provides real-time fact-checking, peer-reviewed insights, and a vast historical knowledge base to support your search.







Contact Us Privacy Policy Disclaimer Terms Of Service

All rights reserved @ 2025 CiteHR ®

All Copyright And Trademarks in Posts Held By Respective Owners.