简体   繁体   中英

Code fires on Workbook_Open, but skips subroutine

Following code is in ThisWorkbook

Private Sub Workbook_Open()
    Call refreshAll
    MsgBox "Queries, Pivot Tables, and PivotCharts have been refreshed!"
    ThisWorkbook.Worksheets("presentation").Activate
End Sub

I'm calling sub refreshAll and Excel "skips" it and executes the rest. refreshAll sub is located in Module1:

Public Sub refreshAll()
    query
    ThisWorkbook.refreshAll
End Sub

What's the problem here? Thanks!

You have to define the Module1 if calling refreshAll() :

Private Sub Workbook_Open()
    Call Module1.refreshAll
    MsgBox "Queries, Pivot Tables, and PivotCharts have been refreshed!"
    ThisWorkbook.Worksheets("presentation").Activate
End Sub

Without Module1.RefreshAll() , your code is executing the ThisWorkbook.RefreshAll() Method.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM