A
AccessUser777 via OfficeKB.com
Hi all,
Need some help on an excel project I've been tasked with. I have an excel
wookbook that has several worksheets. Within the worksheets I have a query
thats pulling data from an MS Access db. I'm trying to create a macro using
VBA to refresh each query in every worksheet. I've seached previous post on
this site and have tried applying some of the codes without much success.
The first code I tried is listed below but it would miss some of the
worksheets and the data on the missed worksheets wouldn't refresh.
Application.DisplayAlerts = False
Sheets("MTD").Select
Range("B5").Select
Selection.QueryTable.Refresh BackgroundQuery:=False
Sheets("DAILY").Select
Range("B5").Select
Selection.QueryTable.Refresh BackgroundQuery:=False
Sheets("WKND").Select
Range("B5").Select
Selection.QueryTable.Refresh BackgroundQuery:=False
Sheets("MTD-DETAIL").Select
Range("B5").Select
Selection.QueryTable.Refresh BackgroundQuery:=False
Sheets("DAILY-DETAIL").Select
Range("B5").Select
Selection.QueryTable.Refresh BackgroundQuery:=False
Sheets("WKND-DETAIL").Select
Range("B5").Select
Selection.QueryTable.Refresh BackgroundQuery:=False
Sheets("DAILY-DETAIL").Select
Range("B5").Select
Selection.QueryTable.Refresh BackgroundQuery:=False
'MESSAGE BOX TO CONFIRM UPDATE IS COMPLETE'
MsgBox ("UPDATES ARE NOW COMPLETE! ")
Next I foud the following code, however, it get a run time error after it
hits the fouth worksheet
Sub GET_VOLUME()
Dim WS As Worksheet
Dim QT As QueryTable
For Each WS In ActiveWorkbook.Worksheets
For Each QT In WS.QueryTables
QT.Refresh
Next QT
Next WS
End Sub
What code should I be using? Am I in the right direction or am I waaaay out
in left field?
Any help is appreciated. Thanks!!!!
Need some help on an excel project I've been tasked with. I have an excel
wookbook that has several worksheets. Within the worksheets I have a query
thats pulling data from an MS Access db. I'm trying to create a macro using
VBA to refresh each query in every worksheet. I've seached previous post on
this site and have tried applying some of the codes without much success.
The first code I tried is listed below but it would miss some of the
worksheets and the data on the missed worksheets wouldn't refresh.
Application.DisplayAlerts = False
Sheets("MTD").Select
Range("B5").Select
Selection.QueryTable.Refresh BackgroundQuery:=False
Sheets("DAILY").Select
Range("B5").Select
Selection.QueryTable.Refresh BackgroundQuery:=False
Sheets("WKND").Select
Range("B5").Select
Selection.QueryTable.Refresh BackgroundQuery:=False
Sheets("MTD-DETAIL").Select
Range("B5").Select
Selection.QueryTable.Refresh BackgroundQuery:=False
Sheets("DAILY-DETAIL").Select
Range("B5").Select
Selection.QueryTable.Refresh BackgroundQuery:=False
Sheets("WKND-DETAIL").Select
Range("B5").Select
Selection.QueryTable.Refresh BackgroundQuery:=False
Sheets("DAILY-DETAIL").Select
Range("B5").Select
Selection.QueryTable.Refresh BackgroundQuery:=False
'MESSAGE BOX TO CONFIRM UPDATE IS COMPLETE'
MsgBox ("UPDATES ARE NOW COMPLETE! ")
Next I foud the following code, however, it get a run time error after it
hits the fouth worksheet
Sub GET_VOLUME()
Dim WS As Worksheet
Dim QT As QueryTable
For Each WS In ActiveWorkbook.Worksheets
For Each QT In WS.QueryTables
QT.Refresh
Next QT
Next WS
End Sub
What code should I be using? Am I in the right direction or am I waaaay out
in left field?
Any help is appreciated. Thanks!!!!