I have a Private Sub Workbook_Open() where I call on a module
Application.OnTime Ontimer_s, "SaveBook"
I need to pass public variables (called for on the workbook object) like:
Option Explicit
Public Ontimer_s As Date
when the code gets to "savebook" module I have brought in variables like shown, but it does not seem to get them correctly. Is this the correct way to do this? I don't think I have a good understanding of subs, modules, macros, and objects, so that may be my main problem.
Public Sub SaveBook(ByVal SavePath As String, ByVal Ontimer_s As Date)
Application.DisplayAlerts = False
ThisWorkbook.SaveAs FileName:=SavePath & ".xlsm", FileFormat:=xlOpenXMLWorkbookMacroEnabled
Ontimer_s = Now() + TimeValue("00:00:01")
Application.OnTime Ontimer_s, "SaveBook" End Sub
Overall I want to save the workbook every second by overwriting a file that I am making through the macro. Maybe there is a better way to do it?