unprotecting sheet with password in macros

alison233

New Member
Joined
Oct 30, 2009
Messages
30
Can anyone help please?

I using an excel workbook (master1) with a macro which opens a sequence of excel workbooks within a specified folder. For every workbook the macro
  • opens each workbook readonly,
  • copies a range of data from the activesheet onto a datasheet 'master1'
  • closes the workbook
It works fine normally, but in this case the active sheet in the workbook is protected with a password (which I know and is the same in all cases). This means my code keeps stopping and I have to manaully enter the password before I can continue. Is there anyway of putting the protection password into my code, so I don't have to enter it manually?

Here is the code
Windows(fname).Activate
ActiveSheet.Unprotect
Here is where it stops and make me enter the password manually

Would be very grateful for any help

Thank you very much
Alison
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
ALISON - hopefully it is as simple as amending your code with the password following the unprotect command:

Windows(fname).Activate
ActiveSheet.Unprotect "password"

ou need the inverted commas, just substitute your password

HTH, cheers, Ian R.
 
Upvote 0
Hi Alison
Change the line to
Code:
ActiveSheet.Unprotect. password "YOUR PASSWORD"
 
Upvote 0
Just add the password after your .Unprotect:
Code:
Activesheet.Unprotect password:="MyPassword"
To protect the sheet again just change the "Unprotect" to "Protect".

The same lines opens the sheets protected without passwords as well.
 
Upvote 0

Forum statistics

Threads
1,214,918
Messages
6,122,257
Members
449,075
Latest member
staticfluids

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