I am starting to learn about workbook queries in Excel 2016. I have a workbook query that I maintain but would like to keep hidden in my workbook and only show the related pivot table reports. Is it possible to refresh the data in the workbook query with the data sheet hidden? I have tried the following, and it works if I leave the sheet visible, but if I hide the sheet I get a run-time 1004 error Select method of worksheet class failed.
Code: Select all
Sub Refresh_Payroll2()
'
' refresh_Payroll Macro
'
'
Sheets("Payroll Research Data").Select
Selection.ListObject.QueryTable.Refresh BackgroundQuery:=False
Sheets("Payroll Research").Select
ActiveSheet.PivotTables("PivotTable2").PivotCache.Refresh
End Sub
I have also tried this code but get a run-time error 438: Object doesn't support this property or method.
Code: Select all
Sub Refresh_Payroll2()
'
' refresh_Payroll Macro
'
'
Sheets("Payroll Research Data").ListObject.QueryTable.Refresh BackgroundQuery:=False
Sheets("Payroll Research").PivotTables("PivotTable2").PivotCache.Refresh
End Sub
Is there a way to refresh the data without making the sheet visible, or would I need to un-hide the sheet, perform the update and then hide it again? If I need to do the latter, how would I code that?
Thanks,
Greg