Jump to content
Sign in to follow this  
Spiff59

Excel - accessing Protected Worksheets

Recommended Posts

I've tried plugging password(s) into the Excel UDF BookOpen routine with no luck.

Is there no way to unlock a protected Excel worksheet, modify a cell or two, and then relock the worksheet?

Thanks.

Share this post


Link to post
Share on other sites

You need to call the Worksheet.Unprotect Method. Then before saving call the Worksheet.Protect Method.

I am sorry if this is a stupid question.. but how would I implement this into my script? Specifically, what would the syntax look like?

I am attempting to unprotect a sheet, make some changes, and then protect it again when done. Thanks for any help you can give!

Share this post


Link to post
Share on other sites

I am sorry if this is a stupid question.. but how would I implement this into my script? Specifically, what would the syntax look like?

I am attempting to unprotect a sheet, make some changes, and then protect it again when done. Thanks for any help you can give!

#include <Excel.au3>

$sFilePath = @ScriptDir & "\Test.xls"
$sPassword = "Password"

$oExcel = _ExcelBookOpen($sFilePath)
With $oExcel.Activesheet
    .Unprotect($sPassword)
    ; Make your changes
    .Protect($sPassword)
EndWith
_ExcelBookSave($oExcel)

Share this post


Link to post
Share on other sites

#include <Excel.au3>

$sFilePath = @ScriptDir & "\Test.xls"
$sPassword = "Password"

$oExcel = _ExcelBookOpen($sFilePath)
With $oExcel.Activesheet
    .Unprotect($sPassword)
    ; Make your changes
    .Protect($sPassword)
EndWith
_ExcelBookSave($oExcel)
Thank you, thank you!! Now that I see it, its seems so easy.. the syntax was eluding me. Thank you again!

Share this post


Link to post
Share on other sites

Hi ,

Thank you for this code it's working fine to unprotect the active sheet.

Can you tell me what is the good syntax for unprotect the workbook too? I think that it should be the Workbook.Unprotect Method or Workbook.UnprotectDocument but I have no idea of the syntax.

Thank you for your help

Loris

Share this post


Link to post
Share on other sites

You can check the syntax on the MSDN page where you can find the Excel object model and the VBA reference.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...