We have the same problem at work as I'm sure many others have had. Someone opens the shared spreadsheet file, then jumps on a conference call, leaves the office, and forgot they left it open. Several hours pass and nobody is able to do any work in the file.
I asked our girl in IT about this, she gave me some VBA, but she is not really versed in it. She claims it works on her computer, but I am unable to get it to work on mine. I am using Excel 365. Others in our office either use that version or a version much older, such as Excel 2016 or even 2013.
This is really a two-part question.
First I copied a test version onto my desktop and saved it as a macro-enabled file (.xlsm).
Next, I followed her instructions to a tee.
First, I opened the workbook and then the Visual Basic Editor by clicking the Developer tab and then Visual Basic. Next I click the Insert tab and selected Module. I entered the following code.
Next I double-clicked on ThisWorkbook, and entered the following code.
According to the lady I spoke with, after 10 minutes of inactivity, it would automatically save and close the file. I modified the time for a single minute (60 seconds), and it just sat there.
Does anybody see anything wrong with the VBA?
The second part of this issue is how do you force Excel to automatically run the VBA content without having to prompt someone to accept it? If we can't get someone to remember to save and close a file when they're finished, they're sure as not going to click a button to accept a macro. They'll just click off it.
Thanks for your time!
Chris
I asked our girl in IT about this, she gave me some VBA, but she is not really versed in it. She claims it works on her computer, but I am unable to get it to work on mine. I am using Excel 365. Others in our office either use that version or a version much older, such as Excel 2016 or even 2013.
This is really a two-part question.
First I copied a test version onto my desktop and saved it as a macro-enabled file (.xlsm).
Next, I followed her instructions to a tee.
First, I opened the workbook and then the Visual Basic Editor by clicking the Developer tab and then Visual Basic. Next I click the Insert tab and selected Module. I entered the following code.
VBA Code:
Dim TheTime As Long
Sub StartTimer()
TheTime = Timer
Application.OnTime Now + TimeValue("00:10:00"), "CloseSave"
End Sub
Sub CloseSave()
If Timer - TheTime > 580 Then
ThisWorkbook.Close SaveChanges:=True
End If
End Sub
Next I double-clicked on ThisWorkbook, and entered the following code.
VBA Code:
style='font-family:inherit;color:#141414'>Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
StartTimer
End Sub
According to the lady I spoke with, after 10 minutes of inactivity, it would automatically save and close the file. I modified the time for a single minute (60 seconds), and it just sat there.
Does anybody see anything wrong with the VBA?
The second part of this issue is how do you force Excel to automatically run the VBA content without having to prompt someone to accept it? If we can't get someone to remember to save and close a file when they're finished, they're sure as not going to click a button to accept a macro. They'll just click off it.
Thanks for your time!
Chris