[英]Using PowerShell, unprotecting an Excel workbook functions correctly, but a worksheet does not
As the title says, I can unprotect the workbook but not the worksheet.正如标题所说,我可以取消保护工作簿但不能保护工作表。 What am I missing?我错过了什么?
Here's the code:这是代码:
$WorkBook = $objExcel.workbooks.Open($_.FullName,0,1) #Path, UpdateLinks, Readonly, Format, Password
$QuoteSheet = $WorkBook.Sheets.Item(1)
$objExcel.AutomationSecurity = 'msoAutomationSecurityForceDisable'
$msoAutomationSecurityForceDisable=3
$WorkBook.unprotect("xxxx") <-- works
$QuoteSheet.unprotect("xxxx") <-- doesn't work
It turns out my workbook was opening to the second worksheet and not the first.事实证明,我的工作簿打开的是第二个工作表,而不是第一个。 While the pride in me would like to see this deleted, an example for how to unprotect workbooks and worksheets using PowerShell should be helpful to others in the future as Google has a hard time finding any.虽然我很自豪希望看到这个被删除,但一个关于如何使用 PowerShell 取消保护工作簿和工作表的示例应该对其他人有所帮助,因为 Google 很难找到任何内容。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.