Hello!
I'm really hoping someone can help me. I have searched and searched and I cannot find a solution that works for me.
Our network at work has an issue that when we share an excel file, if anyone on Windows 7 (most of us are on XP) opens the file, it will automatically unshare it.
So, we needed a file that would close automatically on it's own. I am kinda newbie but I did the following:
ThisWorkbook Code
Private Sub Workbook_Open()
Application.Run "OnTime"
End Sub
Module Code
Sub OnTime()
Application.OnTime Now + TimeValue("00:4:00"), "MyMacro"
End Sub
Sub MyMacro()
MsgBox "Finish up quickly as workbook will automatically close in 1 minute"
Application.OnTime Now + TimeValue("00:01:00"), "CloseMacro"
End Sub
Sub CloseMacro()
Application.DisplayAlerts = False
ThisWorkbook.Save
ThisWorkbook.Close
Application.Quit
End Sub
So the macro runs great when everyone has it enabled, but there is still a problem. If the user lets the macro close the window for them after the 5 minutes, the macro runs perfect. However, if the user closes the window on their own and has other excel windows open still, the code will keep running and after 5 minutes they will get the warning message, the file will re-open on their computer, and the code will keep doing this on a loop.The only way to stop this is to close down ALL excel windows.
I don't have the article but I thought I read somewhere that global time instead of exact time would fix this issue, but I have no idea how to do this. Can someone please help me out and figure out a way to make the timed macro stop if the user closes the excel before the CloseMacro runs and wants to leave their other excel windows open?
This would help so much!!!
I'm really hoping someone can help me. I have searched and searched and I cannot find a solution that works for me.
Our network at work has an issue that when we share an excel file, if anyone on Windows 7 (most of us are on XP) opens the file, it will automatically unshare it.
So, we needed a file that would close automatically on it's own. I am kinda newbie but I did the following:
ThisWorkbook Code
Private Sub Workbook_Open()
Application.Run "OnTime"
End Sub
Module Code
Sub OnTime()
Application.OnTime Now + TimeValue("00:4:00"), "MyMacro"
End Sub
Sub MyMacro()
MsgBox "Finish up quickly as workbook will automatically close in 1 minute"
Application.OnTime Now + TimeValue("00:01:00"), "CloseMacro"
End Sub
Sub CloseMacro()
Application.DisplayAlerts = False
ThisWorkbook.Save
ThisWorkbook.Close
Application.Quit
End Sub
So the macro runs great when everyone has it enabled, but there is still a problem. If the user lets the macro close the window for them after the 5 minutes, the macro runs perfect. However, if the user closes the window on their own and has other excel windows open still, the code will keep running and after 5 minutes they will get the warning message, the file will re-open on their computer, and the code will keep doing this on a loop.The only way to stop this is to close down ALL excel windows.
I don't have the article but I thought I read somewhere that global time instead of exact time would fix this issue, but I have no idea how to do this. Can someone please help me out and figure out a way to make the timed macro stop if the user closes the excel before the CloseMacro runs and wants to leave their other excel windows open?
This would help so much!!!