Vba auto save every 5 minutes. Help

Melmillw82

New Member
Joined
Nov 14, 2017
Messages
27
Hi everyone,
I am trying to auto save a worksheet every 5 mins using vba code. I have saved the code to workbook and module and it saves every 5 mins. Issue is it reopens any excel file that was open and it saves those files too. Any suggestions??
Thanks in advance.

Saved in workbook.

Private Sub Workbook_Open()
alertTime = Now + TimeValue("00:01:00")
Application.OnTime alertTime, "SaveMe"
End Sub

Saved in module

Public Sub SaveMe()
ActiveWorkbook.Save

alertTime = Now + TimeValue("00:01:00")
Application.OnTime alertTime, "SaveMe"
End Sub
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
How about replacing ActiveWorbook.Save with...
Code:
ThisWorkbook.Save
 
Upvote 0
In a Module\
Code:
[color=darkblue]Public[/color] alertTime [color=darkblue]As[/color] [color=darkblue]Date[/color]

[color=darkblue]Public[/color] [color=darkblue]Sub[/color] SaveMe()
    ThisWorkbook.Save
    alertTime = Now + TimeValue("00:01:00")
    Application.OnTime alertTime, "SaveMe"
[color=darkblue]End[/color] [color=darkblue]Sub[/color]


[color=darkblue]Public[/color] [color=darkblue]Sub[/color] SaveMeStop()
    [color=darkblue]On[/color] [color=darkblue]Error[/color] [color=darkblue]Resume[/color] [color=darkblue]Next[/color]
    Application.OnTime alertTime, "SaveMe", Schedule:=[color=darkblue]False[/color]
[color=darkblue]End[/color] [color=darkblue]Sub[/color]

In the Thisworkbook module
Code:
[color=darkblue]Private[/color] [color=darkblue]Sub[/color] Workbook_Open()
    SaveMe
[color=darkblue]End[/color] [color=darkblue]Sub[/color]




[color=darkblue]Private[/color] [color=darkblue]Sub[/color] Workbook_BeforeClose(Cancel [color=darkblue]As[/color] [color=darkblue]Boolean[/color])
    SaveMeStop
[color=darkblue]End[/color] [color=darkblue]Sub[/color]
 
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