[英]subscript out of range excel vba
So i have a macro that does very basic things and it works like a charm. 因此,我有一个宏,它可以执行非常基本的操作,并且它的工作原理就像一种魅力。 However, when anyone else tries opening the sheet and running the macro from their PC, they get the error "Subscript out of range" Please help, it is driving me crazy (:@)
但是,当其他任何人尝试通过他们的PC打开工作表并运行宏时,他们都会收到错误“下标超出范围”。请帮助,这使我发疯(:@)
Sub Refresh()
MSG1 = MsgBox("Are you Connected to (XY) Network?", vbYesNo, "?")
If MSG1 = vbYes Then
MsgBox "Refresh in Progress"
Workbooks("Contact Center Dashboard").Worksheets("CONTACT TRACKER").Activate
ActiveSheet.Range("A4").Select
Selection.ListObject.QueryTable.Refresh BackgroundQuery:=False
'====================='
' Unlock Sheets '
'====================='
Workbooks("Contact Center Dashboard").Worksheets("SUMMARY").Unprotect Password:="nn"
Workbooks("Contact Center Dashboard").Worksheets("DETAILED").Unprotect Password:="nn"
Workbooks("Contact Center Dashboard").Worksheets("ANALYSIS").Unprotect Password:="nn"
'====================='
' Initialize '
'====================='
Dim ptc As PivotTable
'====================='
' Refreshing Dash - 1 '
'====================='
Set ptc = Workbooks("Contact Center Dashboard").Worksheets("SUMMARY").PivotTables("1. CALL SUMMARY - MAIN")
ptc.RefreshTable
'====================='
' Lock Sheet '
'====================='
Workbooks("Contact Center Dashboard").Worksheets("SUMMARY").Protect Password:="nn", AllowUsingPivotTables:=True
Workbooks("Contact Center Dashboard").Worksheets("DETAILED").Protect Password:="nn", AllowUsingPivotTables:=True
Workbooks("Contact Center Dashboard").Worksheets("ANALYSIS").Protect Password:="nn", AllowUsingPivotTables:=True
Workbooks("Contact Center Dashboard").Worksheets("SUMMARY").Activate
MsgBox "Dashboard Successfully Refresshed"
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 XY local network or through VPN " & vbNewLine & "2- Click (REFRESH DATA)"
End If
End Sub
This is the final working script for reference in case anyone has a simmilar issue in the future 这是最终的工作脚本,以备将来有人遇到类似问题时参考
Sub Refresh()
MSG1 = MsgBox("Are you Connected to (XY) Network?", vbYesNo, "?")
If MSG1 = vbYes Then
MsgBox "Refresh in Progress"
ActiveWorkbook.Worksheets("CONTACT TRACKER").Activate
ActiveSheet.Range("A4").Select
Selection.ListObject.QueryTable.Refresh BackgroundQuery:=False
'====================='
' Unlock Sheets '
'====================='
ActiveWorkbook.Worksheets("SUMMARY").Unprotect Password:="nn"
ActiveWorkbook.Worksheets("DETAILED").Unprotect Password:="nn"
ActiveWorkbook.Worksheets("ANALYSIS").Unprotect Password:="nn"
'====================='
' Initialize '
'====================='
Dim ptc As PivotTable
'====================='
' Refreshing Dash - 1 '
'====================='
Set ptc = ActiveWorkbook.Worksheets("SUMMARY").PivotTables("1. CALL SUMMARY - MAIN")
ptc.RefreshTable
'====================='
' Lock Sheet '
'====================='
ActiveWorkbook.Worksheets("SUMMARY").Protect Password:="nn", AllowUsingPivotTables:=True
ActiveWorkbook.Worksheets("DETAILED").Protect Password:="nn", AllowUsingPivotTables:=True
ActiveWorkbook.Worksheets("ANALYSIS").Protect Password:="nn", AllowUsingPivotTables:=True
ActiveWorkbook.Worksheets("SUMMARY").Activate
MsgBox "Dashboard Successfully Refresshed"
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 XY local network or through VPN " & vbNewLine & "2- Click (REFRESH DATA)"
End If
End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.