How to run a macro behind a Password Protected excel workbook

chrisandsally

New Member
Joined
Feb 6, 2015
Messages
4
Hi

I have the following code that worked until the excel workbook was required to be password protected. It fails when I added the password attribute.

Code:
Option Explicit


Dim xlApp, xlBook


Set xlApp = CreateObject("Excel.Application")
'~~> Change Path here
Set xlBook = xlApp.Workbooks.Open("\\server\a\Rota.xlsm", 0, True, Password:="1234")


xlApp.Run "CreateOpsRota"
xlBook.Close
xlApp.Quit


Set xlBook = Nothing
Set xlApp = Nothing


WScript.Echo "Finished."
WScript.Quit

Any help really appreciated.

Thanks
 
It looks like you're running this in VBScript which doesn't like named arguments - you have to use positional ones:

Code:
Set xlBook = xlApp.Workbooks.Open("\\server\a\Rota.xlsm", 0, True, , "1234")
 
Upvote 0
It looks like you're running this in VBScript which doesn't like named arguments - you have to use positional ones:

Code:
Set xlBook = xlApp.Workbooks.Open("\\server\a\Rota.xlsm", 0, True, , "1234")



Thank you RoryA I will try that. Thank you for your help.

Kyle123 Sorry for Xposting without URL's I thought your message was to the reply above not to me.
 
Upvote 0

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