VBA: Open Password protected file in Excel

unknownymous

Board Regular
Joined
Sep 19, 2017
Messages
249
Office Version
  1. 2016
Platform
  1. Windows
Hello Gurus,

Basically, I need to open password protected PDF file even on read-only. I found this code online and wanted to ask if you can help to update the code.

= = = =
Sub Workbook_Open()
Application.DisplayAlerts = False
'Change 1234 to your file password accordingly

Dim pdfPath As String
pdfPath = Application.GetOpenFilename(filefilter:="PDF file (*.pdf), *.pdf")
Call OpenAnyFile(pdfPath)

Workbooks.Open Filename:="C:\Users\file.xls",
Password:="1234", ReadOnly:=True
Application.DisplayAlerts = True
End Sub

= = = = == = =
To do: I'll run the macro via excel and will no longer put the password over and over again since it is included in the code. Also, I'd like to use the option of asking for pathfolder and will choose the specific PDF file. Open as read only is fine.


Any help will be much appreciated.

Thank you!
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
Some of the code is missing, it appears.

Do you have the full code?
 
Upvote 0
Some of the code is missing, it appears.

Do you have the full code?
Hello! Thanks for looking into this but that's the code I found and was only suggested. If you have any other codes, that would be appreciated. :)
 
Upvote 0

Forum statistics

Threads
1,221,418
Messages
6,159,791
Members
451,589
Latest member
Harold14

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