Good Afternoon,
I want to create an Excel Spreadsheet which automatically closes after a certain time of being idle as multiple users need access to it.
I have found coding for that but unfortunately for it to work Macros need to be enabled.
I have found what I need which works separately but I'm not sure how to combine the two and Excel keeps throwing up errors
1) Enable Macro (took from the below website)
Close Excel after a certain time in macro (took from below)
ALT+F11 to open VB editor. Double click 'ThisWorkbook' and paste the first 2 modules in on the right.
Private Sub Workbook_Open()
StartTimer
End Sub
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
StartTimer
End Sub
Now right click 'ThisWorkbook' insert module and paste this code in. Save close and re-open the workbook and after 15 minutes of idle time it will save and close automatically.
Const idleTime = 900 'seconds
Dim Start
Sub StartTimer()
Start = Timer
Do While Timer < Start + idleTime
DoEvents
Loop
Application.DisplayAlerts = False
ActiveWorkbook.Close True
Application.DisplayAlerts = True
End Sub
I would appreciate some help how I can combine the two please to get the spreadsheet working.
Thank you,
I want to create an Excel Spreadsheet which automatically closes after a certain time of being idle as multiple users need access to it.
I have found coding for that but unfortunately for it to work Macros need to be enabled.
I have found what I need which works separately but I'm not sure how to combine the two and Excel keeps throwing up errors
1) Enable Macro (took from the below website)
Make Users Enable Macros in Order to View a Workbook in Excel - TeachExcel.com
Tutorial showing you how to make a user enable macros in a workbook in order to view the workbook This is very important when macros make up a critical part of the workbook and not having them can sto ...
www.teachexcel.com
[ICODE]Private Sub Workbook_Open()
[/ICODE][ICODE]'worksheets to show when macro is enabled
[/ICODE][ICODE]Sheets("Data").Visible = True
[/ICODE][ICODE]'worksheet that shows reminder to enable macro
[/ICODE][ICODE]Sheets("Reminder").Visible = xlVeryHidden
[/ICODE][ICODE]End Sub
[/ICODE][ICODE]Private Sub Workbook_BeforeClose(Cancel As Boolean)
[/ICODE][ICODE]'worksheet with reminder
[/ICODE][ICODE]Sheets("Reminder").Visible = True
[/ICODE][ICODE]'worksheets to show when macro is enabled
[/ICODE][ICODE]Sheets("Data").Visible = xlVeryHidden
[/ICODE][ICODE]ThisWorkbook.Save
[/ICODE][ICODE]End Sub
[/ICODE]Close Excel after a certain time in macro (took from below)
[ICODE]https://answers.microsoft.com/en-us/msoffice/forum/all/a-simple-macro-to-save-and-close-a-excel/7cdbbf10-3e83-4d2e-990c-811cec8eda55
[/ICODE]ALT+F11 to open VB editor. Double click 'ThisWorkbook' and paste the first 2 modules in on the right.
Private Sub Workbook_Open()
StartTimer
End Sub
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
StartTimer
End Sub
Now right click 'ThisWorkbook' insert module and paste this code in. Save close and re-open the workbook and after 15 minutes of idle time it will save and close automatically.
Const idleTime = 900 'seconds
Dim Start
Sub StartTimer()
Start = Timer
Do While Timer < Start + idleTime
DoEvents
Loop
Application.DisplayAlerts = False
ActiveWorkbook.Close True
Application.DisplayAlerts = True
End Sub
I would appreciate some help how I can combine the two please to get the spreadsheet working.
Thank you,