美好的一天,
我正在尝试刷新工作表上的表格,然后通过使用VBA刷新数据透视表
一切都运行良好,除了我尝试刷新到枢轴的部分,更具体地说是“pt.RefreshTable”代码
Sub Refresh()
MSG1 = MsgBox("Are you Connected to (local) Network?", vbYesNo, "?")
If MSG1 = vbYes Then
MsgBox "Refresh in Progress"
Workbooks("Sharepoint Dispute Management Dashboard").Worksheets("Dispute Data").Activate
ActiveSheet.Range("A4").Select
Selection.ListObject.QueryTable.Refresh BackgroundQuery:=False
'====================='
' Unlock Sheets '
'====================='
Workbooks("Sharepoint Dispute Management Dashboard").Worksheets("Dash - 1").Activate
Workbooks("Sharepoint Dispute Management Dashboard").Worksheets("Dash - 1").Unprotect Password:="n"
'====================='
' Initialize '
'====================='
Dim pt As PivotTable
'====================='
' Refreshing Dash - 1 '
'====================='
Set pt = Workbooks("Sharepoint Dispute Management Dashboard").Worksheets("Dash - 1").PivotTables("Dash1-Resolved")
pt.RefreshTable
'====================='
' Lock Sheet '
'====================='
Workbooks("Sharepoint Dispute Management Dashboard").Worksheets("Dash - 1").Protect Password:="n", AllowUsingPivotTables:=True
Else
MsgBox "You can still use the dashboard but the numbers will not be updated" & vbNewLine & vbNewLine & vbNewLine & "To get the latest update, do the following:" & vbNewLine & vbNewLine & "1- Please connect to the local network or through VPN " & vbNewLine & "2- Click (REFRESH DATA)"
End If
End Sub
答案 0 :(得分:0)
显然我已将其他工作表锁定,其中包含与我正在尝试刷新的工作表相关联的其他工具。 我所做的就是添加了一个代码来解锁工作簿中的所有工作表,刷新数据透视表,然后再次锁定它们。工作就像一个魅力。
希望这对将来面临类似问题的任何人都派上用场