【发布时间】:2018-09-15 08:06:59
【问题描述】:
我遇到了一个宏的小问题,它假设取消保护我的工作表、刷新数据透视表并再次保护 ws(有条件)。它只是部分工作正常,因为它确实取消了对 ws 的保护,它刷新了数据透视表,但之后发生了一些奇怪的事情: - 它并没有真正恢复行和列格式 - 它不能正确保护 ws(当您单击工具、保护时,我的 ws 看起来像是受到保护 - 但是,您可以在不再次输入密码的情况下取消保护它??!!
Sub RefreshPivotTables()
' will remove password and refresh PT
Dim xpt As PivotTable
With ActiveSheet
.Unprotect Password:="milessss"
For Each xpt In Worksheets("WT-1").PivotTables
xpt.RefreshTable
Next xpt
.Protect Password:="milessss", AllowFormattingCells:=True, _
AllowFormattingRows:=True, AllowFormattingColumns:=True, _
AllowUsingPivotTables:=True, EnableOutlining:=True
End With
End Sub
有人可以帮忙吗? 干杯 - Mile`S
【问题讨论】:
标签: vba excel excel-2003