I created a Macro that closes the WB after some time of inactivity. It works perfect if I manually open the file, but if I use another macro from a different WB to open the
try adding a stop statement to your workbook_open to test if the event is even being triggered
Private Sub Workbook_Open()
start_Countdown
Stop
End Sub
this would be a brute force way the to run the open Event from the Calling Workbook.
Application.Run(ActiveWorkbook.name & "!Workbook_Open")
add this just after you open the Workbook.
As Susilo pointed out in the comments, the issue must be something else than the auto-close code itself, since it works. That "something else" then, is probably the Answer_Quote()
code, which frankly is one big mess. I'd recommend the following:
USE DUMMY CODE
Try running a dummy macro (a macro that essentially does nothing but open the workbook that should auto-close after some inactivity) instead of Answer_Quote()
to see if the problem persists. If it doesn't, then you know for sure that Answer_Quote()
is causing the problem. Proceed then to code cleanup.
CODE CLEANUP
1) Set all objects, external file and sheet references to nothing upon exit.
Optionally and thus less importantly, but to ease code maintenance and debugging, I'd also recommend:
2) Use proper and consistent indentation
3) Remove redundant lines of code
For instance:
If wBook Is Nothing Then 'Not open
Set wBook = Nothing
It is obviously pointless to set a reference to nothing if it is already nothing.
4) Dimension all variables at the top, rather than throughout the code.
5) Use Option explicit
(if you don't already)
TEST AUTO-CLOSE EXECUTION
After code cleanup, test again. If the problem persists, try commenting out some of theAnswer_Quote()
code and try again. Repeat this process until the auto-close execution works again and you can pinpoint the exact cause of the problem.