Application.Ontime switching workbooks

Afro_Cookie

Board Regular
Joined
Mar 17, 2020
Messages
103
Office Version
  1. 365
Platform
  1. Windows
This is a continuation of a post that is now buried. Application.OnTime continuously opening my workbook The Code @AlphaFrog helped with is working perfectly.

Each instance of save, the workbook comes to the foreground and then to the background again after the save is completed. While this is minor it is really inconvenient to see something flashing on your screen every 10 seconds.

Not too sure how to phrase this, but can the save feature be run in the background only so that it won't flash each 10 seconds?
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Try this
VBA Code:
Sub SaveThis()

    Dim bScrn   As Boolean
    
    With Application
        bScrn = .ScreenUpdating
        .ScreenUpdating = False
        .DisplayAlerts = False
        ThisWorkbook.Save
        .DisplayAlerts = True
    
        NextTime = Now + TimeValue("00:00:10")
        .OnTime NextTime, "SaveThis"
        .ScreenUpdating = bScrn
    End With
End Sub
 
Upvote 0
Unfortunately no change.

Try this
VBA Code:
Sub SaveThis()

    Dim bScrn   As Boolean
   
    With Application
        bScrn = .ScreenUpdating
        .ScreenUpdating = False
        .DisplayAlerts = False
        ThisWorkbook.Save
        .DisplayAlerts = True
   
        NextTime = Now + TimeValue("00:00:10")
        .OnTime NextTime, "SaveThis"
        .ScreenUpdating = bScrn
    End With
End Sub
 
Upvote 0
Update: Does Excel have to switch to the workbook it's saving in order to do the save? Can it be done in the background, like autosave?
 
Upvote 0
Saving a file by means of a macro can always take place in the background. I am not sure (because I've never used the OnTime method till now ...) but I think this is VBA native behavior when using OnTime. Excel seems to switch to the workbook that contains the OnTime macro. I just did a little test and it turns out that even a closed workbook reopens to run an OnTime macro. Therefore an alternative would be to introduce a homemade AddIn for placing the OnTimeSave macro in there, however some adjustments to your code would be neccesary.
 
Upvote 0

Forum statistics

Threads
1,223,948
Messages
6,175,571
Members
452,652
Latest member
eduedu

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