wait after workbook is saved

zico8

Board Regular
Joined
Jul 13, 2015
Messages
227
hi,

I need to refresh Query (PQ) after file saving.
Is there any way to check if is fully saved before executing next line?

In below code if any user would switch sheets very quickly I get run-time error.


Code:
Private Sub Worksheet_Activate()
ActiveWorkbook.Save
ActiveWorkbook.Connections("Query - Total Query").Refresh
End Sub
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
Looks like you need to use the AfterSave event:

Code:
Private Sub Workbook_AfterSave(ByVal Success As Boolean)
    If Success Then ActiveWorkbook.Connections("Query - Total Query").Refresh
End Sub
 
Upvote 0
Thanks VBA Geek,

but it does not solve the problem.

If I very quikly switch between sheets (Ctrl+PgUp, Ctrl+PgDn) I get run-time error.
 
Upvote 0
Thanks VBA Geek,

but it does not solve the problem.

If I very quikly switch between sheets (Ctrl+PgUp, Ctrl+PgDn) I get run-time error.


try to UN-check "enable background refresh" so you wont be able to switch between tabs whilst it is refreshing

C5eNtCm.png
 
Upvote 0
I have this option unchecked and tabs not change during refreshing but error appears.
 
Upvote 0
when does the error happen, during the refreshing of the query or during the file getting saved? and what is the error?
 
Upvote 0
then it has nothing to do with PQ.. your file is not getting saved. probably has become corrupted I guess
 
Upvote 0
hi,

I need to refresh Query (PQ) after file saving.
Is there any way to check if is fully saved before executing next line?

In below code if any user would switch sheets very quickly I get run-time error.


Code:
Private Sub Worksheet_Activate()
ActiveWorkbook.Save
ActiveWorkbook.Connections("Query - Total Query").Refresh
End Sub

See if this works :
Code:
Private Sub Worksheet_Activate()
    [COLOR=#ff0000][B]ThisWorkbook[/B][/COLOR].Save
    [B][COLOR=#ff0000]ThisWorkbook[/COLOR][/B].Connections("Query - Total Query").Refresh
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,164
Messages
6,170,444
Members
452,326
Latest member
johnshaji

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top