Jump to content

Excel - accessing Protected Worksheets


Recommended Posts

  • 7 months later...

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!

Link to comment
Share on other sites

  • Moderators

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)
Link to comment
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!
Link to comment
Share on other sites

  • 4 months later...

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

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...