Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with Password

Status
Not open for further replies.
Oct 11, 2007
44
US
When I run the macro, How do I unprotect the workbook and worksheets automatically , and then protect them again via VBA when the macro has been completely run?


Can anyone help ?

To Run the macro:
1. Save the Template on C:\ as Template1.xls
2. Click Run on TestMacro.xls
3. Select SourceFile3.xls to process
4. File is saved at C:\

File is saved at:
Thanks
 

OOPS!!

I made a typo error in my last post. The BeforeClose code should read:

Code:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
ActiveWorkbook.Protect ("Valuation")
ActiveWorkSheets.Protect ("Valuation")
End Sub

This is a result of being in a hurry and doing a copy/paste without making the needed change (removing the "Un") once the code was pasted in its new location.

Sorry about that!

[sadeyes]

----------------------------------------------------------------------------------
"A committee is a life form with six or more legs and no brain." -- L. Long
 
I certainly agree about being confused - which file is it that needs 'unprotecting', which sheets?
Maybe you could step through the macro and tell us the exact lines where the prompts for a password occur, or where the the code fails because a sheet is protected. For each tell us how you would resolve this WITHOUT CODE.

If you are prompted for a password immediately the file is opened then open the workbook manually go to Files,Save As, Tools,General options and tell us what you see - which password box is completed, is the ReadOnly recommended box ticked?
You will then need to include the password in the command line that opens the file.

By the way, building on WalkerEvans idea, if you want extra security there is a way of hiding a sheet so it can only be unhidden through code or the VBA editor.

Gavin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top