[英]VBA - Method Activate of Worksheet Failed?
我下面的代碼有什么問題?
我有一個錯誤
工作表的方法激活失敗
Sub addMOnth()
Dim ws As Worksheet
For Each ws In ActiveWorkbook.Worksheets
ws.Activate
If ws.Name <> "SUMMARY" And ws.Name <> "Store" And ws.Name <> "Apps" Then
ActiveSheet.PivotTables("PivotTable1").PivotFields( _
"[Report Date Structure].[Month].[Month]").VisibleItemsList = Array( _
"[Report Date Structure].[Month].&[2.01711E5]")
End If
Next ws
End Sub
無需Activate
ws
僅過濾PivotTable
。
嘗試以下代碼,並在代碼注釋中進行解釋:
Sub addMOnth()
Dim ws As Worksheet
For Each ws In ThisWorkbook.Worksheets
With ws
Select Case .Name
Case "SUMMARY", "Store", "Apps"
' do nothing
Case Else ' equivalent to your If with multiple AND
.PivotTables("PivotTable1").PivotFields( _
"[Report Date Structure].[Month].[Month]").VisibleItemsList = Array( _
"[Report Date Structure].[Month].&[2.01711E5]")
End Select
End With
Next ws
End Sub
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.