VBScript to open a password protected file in order to edit links.

rdomingue

New Member
Joined
Mar 18, 2016
Messages
8
I have a working program but want to add a password to the external file I'm using to update my active spreadsheet file. I do not want to be prompted for the password when I initiate the "update" command from within code. I would like to automatically pass the password through scripting. Here is what I have so far: (This works if I don't password protect the file "activityreportdatabase.xlxs.")

Sub GetLinks()
' UpdateLinks Macro


Dim Response As Integer, PASSWORD As String
Response = MsgBox(prompt:="UPDATE NOW?", Buttons:=vbYesNo)
If Response = vbYes Then
ActiveSheet.Unprotect ("456")
ActiveWorkbook.UpdateLink Name:="C:\activityreportdatabase.xlsx", Type:= _
xlExcelLinks
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
ActiveSheet.Protect ("456")
Else
End If
End Sub
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
The 'Workbooks.Open' method has a password parameter you can use to open a password protected spreadsheet. So if Book1.xlsx on your desktop is password protected with the word "test" you would use this code to open the workbook:

Code:
Workbooks.Open Environ$("UserProfile") & "\Desktop\Book1.xlsx",Password:="test"
 
Upvote 0

Forum statistics

Threads
1,215,327
Messages
6,124,292
Members
449,149
Latest member
mwdbActuary

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