Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
excel vba透视表刷新错误_Excel_Vba_Refresh_Pivot - Fatal编程技术网

excel vba透视表刷新错误

excel vba透视表刷新错误,excel,vba,refresh,pivot,Excel,Vba,Refresh,Pivot,你好 我正在尝试刷新工作表上的表,然后使用VBA刷新透视表 除了我尝试刷新到pivot的部分(更具体地说是pt.refreshttable代码)之外,一切都运行良好 Sub Refresh() MSG1 = MsgBox("Are you Connected to (local) Network?", vbYesNo, "?") If MSG1 = vbYes Then MsgBox "Refresh in Progress" Workbooks("Sharepoint Dispute Ma

你好

我正在尝试刷新工作表上的表,然后使用VBA刷新透视表

除了我尝试刷新到pivot的部分(更具体地说是pt.refreshttable代码)之外,一切都运行良好

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

显然,我锁定了其他工作表,其中包含链接到我试图刷新的工作表的其他轴。 我所做的只是添加了一个代码来解锁工作簿中的所有工作表,刷新透视,然后再次锁定它们。工作得很有魅力


希望这对将来遇到类似问题的人有用

我收到一个运行时错误-1004。这是与对象相关的。但是,我尝试初始化所有对象,但没有使用