Greetings, I have a WB that is used among my department. If one user 'forgets' to close the WB, it locks everyone else out. I've tried using a SHARED WB, but that has lead to other issues, and from what read, it's just as well that I don't use a SHARED WB.
To my point...I was given reference to http://www.cpearson.com/Excel/OnTime.aspx and have attempted to use the provided example. When I use the line of
ThisWorkbook.Close SaveChanges:=False
the entire Excel application gets closed. I only want to close the WB, in case the user has other WB's open, I don't need to disturb them.
Here's the code I have, no other code is in the WB.
Public Declare Function SetTimer Lib "user32" ( _
ByVal HWnd As Long, _
ByVal nIDEvent As Long, _
ByVal uElapse As Long, _
ByVal lpTimerFunc As Long) As Long
Public Declare Function KillTimer Lib "user32" ( _
ByVal HWnd As Long, _
ByVal nIDEvent As Long) As Long
Public TimerID As Long
Public TimerSeconds As Single
Public Sub StartTimer()
TimerSeconds = 10 ' how often to "pop" the timer.
TimerID = SetTimer(0&, 0&, TimerSeconds * 1000&, AddressOf TimerProc)
End Sub
Public Sub TimerProc(ByVal HWnd As Long, ByVal uMsg As Long, ByVal nIDEvent As Long, ByVal dwTimer As Long)
KillTimer 0&, TimerID
ChDrive "C"
ChDir "C:\Temp"
With ThisWorkbook
'Save a TEMP file - just incase.
.SaveAs Filename:=Left(ThisWorkbook.Name, Len(ThisWorkbook.Name) - 5) & " " & Format(Now(), "mmddyy hhmm"), _
FileFormat:=xlOpenXMLWorkbookMacroEnabled, _
AccessMode:=xlExclusive, _
AddToMRU:=True
.Close SaveChanges:=False '<<<<---- THIS IS THE OFFENDING LINE
End With
End Sub
You help is appreciated...
Bookmarks