worksheet reopening

allanon1

New Member
Joined
Jan 6, 2010
Messages
20
I am using the code at the end of this post to make the sheet autosave every x minutes. The autosave function works perfectly.
The issue is if there is another excel file open at the time of close the autosave sheet reopens at the time it would have saved.
There is another excel file that is always open as it is a required log.

Any ideas would be great. Thanks.

In Workbook
Private Sub Workbook_Open()
Application.OnTime Now + TimeValue("00:05:00"), "SaveThis"
End Sub

In a module
Sub SaveThis()
Application.DisplayAlerts = False
ThisWorkbook.Save
Application.DisplayAlerts = True


Application.OnTime Now + TimeValue("00:05:00"), "SaveThis"
End Sub
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
I guess I don't understand the probelem. The code activates the OnTime function once the workbook is opened and will autosave the workbook every five minutes so long as you have the workbook open. I expect that what you are seeing is the 'SaveThis' macro activativating the host workbook when the code runs. I am not sure this will fix it, but you can try it and see.

Code:
Sub SaveThis()
Application.DisplayAlerts = False
App[lication.ScreenUpdating = False
ThisWorkbook.Save
Application.DisplayAlerts = True
Application.ScreenUpdating = True
Application.OnTime Now + TimeValue("00:05:00"), "SaveThis"
End Sub
 
Upvote 0
Nope sorry. I replaced my code of
Sub SaveThis()
Application.DisplayAlerts = False
ThisWorkbook.Save
Application.DisplayAlerts = True
Application.OnTime Now + TimeValue("00:05:00"), "SaveThis"
End Sub

with your code of
Sub SaveThis()
Application.DisplayAlerts = False
Application.ScreenUpdating = False
ThisWorkbook.Save
Application.DisplayAlerts = True
Application.ScreenUpdating = True
Application.OnTime Now + TimeValue("00:05:00"), "SaveThis"
End Sub

shortened the save time to 1 minute. the autosave worked fine. but when I closed the workbook with other excel workbooks open it reopened it 1 minute later.

Thank you for the attempt however.
 
Upvote 0
Would there be a way to include in the script to verify the particular workbook it open, as opposed to just any workbook, before the autosave kicks in?
 
Upvote 0
You have a second line of code that resets the OnTime function to run the SaveThis macro, so it will re-open the workbook and save it every time period specified. You could include a 'ThisWorkbook.Close False' line after the secong 'OnTime' statement that would close the workbook once saved. That way you would only have a temporary interuption.
 
Upvote 0
Maybe I should elaborate a little. The 'SaveThis' macro is a self perpetuating macro, which means that once initiated, it will continue calling itself until manual interventions stops it or it causes a memory problem.
Since it does not make sense to continually save a closed workbook (no changes being made) the save action is initiated with the workbook open and when that happens, it becomes the active workbook per Excel protocol. You could put a statement at the beginning of the macro like:
Code:
If Application.Workbooks.Count > 1 Then Exit Sub
Which would prevent the Save action from executing.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,819
Messages
6,181,153
Members
453,021
Latest member
Justyna P

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