简体   繁体   English

使用 PowerShell,取消保护 Excel 工作簿可以正常工作,但工作表不能

[英]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.

相关问题 使用 powershell 从 excel 工作簿中删除工作表 - Delete worksheet from excel workbook using powershell PowerShell-Excel-在工作簿中选择第一个工作表 - PowerShell - Excel - Select first worksheet in workbook 如何使用php在Excel工作簿中添加工作表 - how to add worksheet in the excel workbook using php 使用 xlwings 刷新工作簿中的单个工作表(excel) - Refresh single worksheet (excel) in workbook using xlwings 使用Powershell将Excel工作表从一个工作簿复制到另一个工作簿 - Copy Excel Worksheet from one Workbook to another with Powershell 使用单元格引用作为工作簿和工作表的名称来激活Excel工作簿/工作表 - Activating Excel Workbook/Sheet using cell reference as name of Workbook and Worksheet 使用vba删除其他excel工作簿中excel工作表上的空白行 - delete blank rows on an excel worksheet, in a different excel workbook, using vba 使用python使用excel工作表(具有所需条件)创建excel工作簿 - Creating excel workbook using excel worksheet (with required condition) using python 如何使用工作簿和工作表的变量将数据从一个 Excel 工作簿复制到另一个 Excel 工作簿? - How can I copy data from one Excel workbook to another Excel workbook using variables for Workbook and Worksheet? 使用PowerShell Excel每个工作表内存使用情况 - Excel each worksheet memory usage using powershell
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM