Code Problem

D

Drew

I am trying to click on a command button in a worksheet that will refresh
pivot tables and ODBC connections throughout my workbook. The code seems to
work well to refresh the pivot tables, but once it hits the ODBC data it
errors out.

Can someone help me with my code?

Sheets("Sheet1").PivotTables("PivotTable1").RefreshTable
Sheets("Sheet2").PivotTables("PivotTable1").RefreshTable
Sheets("Sheet3").Select
Range("A1").Select
Selection.QueryTable.Refresh BackgroundQuery:=False
Sheets("Sheet4").Select
Range("A1").Select
Selection.QueryTable.Refresh BackgroundQuery:=False
 
S

smartin

Drew said:
I am trying to click on a command button in a worksheet that will refresh
pivot tables and ODBC connections throughout my workbook. The code seems to
work well to refresh the pivot tables, but once it hits the ODBC data it
errors out.

Can someone help me with my code?

Sheets("Sheet1").PivotTables("PivotTable1").RefreshTable
Sheets("Sheet2").PivotTables("PivotTable1").RefreshTable
Sheets("Sheet3").Select
Range("A1").Select
Selection.QueryTable.Refresh BackgroundQuery:=False
Sheets("Sheet4").Select
Range("A1").Select
Selection.QueryTable.Refresh BackgroundQuery:=False

Maybe this will work better for you. Works equally well for pivot tables
and ODBC sources.

Sub RefreshAllPivotTables_n_Such()
ActiveWorkbook.RefreshAll
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top