cancel
Showing results for 
Search instead for 
Did you mean: 

VBA + Refresh referencing sheet name instead of selecting/activating

b5noj
Explorer
0 Kudos

Hi

Is it possible to refresh and EPM report without activating or selecting a sheet?? I've always been told it's not good practice to select or activate a sheet when writing VBA.

Example - Current method

Dim api As Object
api = Application.COMAddIns("FPMXLClient.Connect").Object
Sheet1.activiate
api.Refresh

Example - What I'd like to use

Dim api As Object
api = Application.COMAddIns("FPMXLClient.Connect").Object
Sheet1.api.Refresh
former_member186338
Active Contributor
0 Kudos

P.S. Please accept correct answer to your previous question!

View Entire Topic
former_member186338
Active Contributor
0 Kudos

Sorry, but there is no API that will refresh some particular sheet without activating it.

"I've always been told it's not good practice to select or activate a sheet when writing VBA." - wrong idea!

You can always store current active sheet in some variable, then activate sheet to be refreshed, then activate sheet saved in variable.

Dim wshCurrent as Worksheet
Set wshCurrent = ThisWorkbook.ActiveSheet 'store current active sheet
ThisWorkbook.Worksheets("SheetWithReportName").Activate
api.RefreshActiveSheet
wshCurrent.Activate 'restore active sheet