Pivot Table Refresh Macro

K

kgottl01

I found this code for creating a macro that refreshes a pivot table's
connection to a database that's in the same folder as the excel file.
I want to be able to change the path so it will reference a database in
another location. When I change the ActiveWorkbook.Path to the
database path "Q:\RLT\RLT.mdb", it says it's connecting to the
database, but the new data does not update the pivot table. How should
I modify?

Sub RefreshPivot()
Dim myConnect As String
myConnect = "ODBC;"
myConnect = myConnect & _
"Driver={Microsoft Access Driver (*.mdb)};"
myConnect = myConnect & "DBQ="
myConnect = myConnect & ActiveWorkbook.Path
ActiveWorkbook.PivotCaches(1).Connection = myConnect
ActiveWorkbook.PivotCaches(1).Refresh
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