ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Excel can't find macro (https://www.excelbanter.com/excel-discussion-misc-queries/247141-excel-cant-find-macro.html)

dhstein

Excel can't find macro
 
This is a strange and difficult issue. I'm running Application.OnTime to
close a shared workbook after 1 hour of inactivity. This prevents a user
from locking up the workbook. When testing this on my home computer, it
works well. However on the system at work there is a problem. It seems if
the user is another workbook, Excel can't find the "SaveAndClose " macro (I
don't recall the exact error message - something like "unable to locate macro
"SaveAndClose". I do the same thing at home and it works fine. Any ideas on
what could be causing this? The macro is shown below and is in the
"ThisWorkbook" code. The SaveAndClose macro is in a general module. Thanks.

Private Sub Workbook_Open()
On Error Resume Next
Application.OnTime RunWhen, "SaveAndClose", , False
On Error GoTo 0
RunWhen = Now + TimeSerial(0, NUM_MINUTES, 0)
Application.OnTime RunWhen, "SaveAndClose", , True
End Sub

Private Sub Workbook_BeforeClose(Cancel As Boolean)
On Error Resume Next
Application.OnTime RunWhen, "SaveAndClose", , False
On Error GoTo 0
End Sub

Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
On Error Resume Next
Application.OnTime RunWhen, "SaveAndClose", , False
On Error GoTo 0
RunWhen = Now + TimeSerial(0, NUM_MINUTES, 0)
Application.OnTime RunWhen, "SaveAndClose", , True
End Sub

Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, _
ByVal Target As Range)

On Error Resume Next
Application.OnTime RunWhen, "SaveAndClose", , False
On Error GoTo 0
RunWhen = Now + TimeSerial(0, NUM_MINUTES, 0)
Application.OnTime RunWhen, "SaveAndClose", , True

End Sub

Barb Reinhardt

Excel can't find macro
 
Where are you defining RUNWHEN and NUM_MINUTES?

"dhstein" wrote:

This is a strange and difficult issue. I'm running Application.OnTime to
close a shared workbook after 1 hour of inactivity. This prevents a user
from locking up the workbook. When testing this on my home computer, it
works well. However on the system at work there is a problem. It seems if
the user is another workbook, Excel can't find the "SaveAndClose " macro (I
don't recall the exact error message - something like "unable to locate macro
"SaveAndClose". I do the same thing at home and it works fine. Any ideas on
what could be causing this? The macro is shown below and is in the
"ThisWorkbook" code. The SaveAndClose macro is in a general module. Thanks.

Private Sub Workbook_Open()
On Error Resume Next
Application.OnTime RunWhen, "SaveAndClose", , False
On Error GoTo 0
RunWhen = Now + TimeSerial(0, NUM_MINUTES, 0)
Application.OnTime RunWhen, "SaveAndClose", , True
End Sub

Private Sub Workbook_BeforeClose(Cancel As Boolean)
On Error Resume Next
Application.OnTime RunWhen, "SaveAndClose", , False
On Error GoTo 0
End Sub

Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
On Error Resume Next
Application.OnTime RunWhen, "SaveAndClose", , False
On Error GoTo 0
RunWhen = Now + TimeSerial(0, NUM_MINUTES, 0)
Application.OnTime RunWhen, "SaveAndClose", , True
End Sub

Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, _
ByVal Target As Range)

On Error Resume Next
Application.OnTime RunWhen, "SaveAndClose", , False
On Error GoTo 0
RunWhen = Now + TimeSerial(0, NUM_MINUTES, 0)
Application.OnTime RunWhen, "SaveAndClose", , True

End Sub


Barb Reinhardt

Excel can't find macro
 
Have you tried

Application.Run "'" & thisworkbook.name & "'!SaveAndClose"

"dhstein" wrote:

This is a strange and difficult issue. I'm running Application.OnTime to
close a shared workbook after 1 hour of inactivity. This prevents a user
from locking up the workbook. When testing this on my home computer, it
works well. However on the system at work there is a problem. It seems if
the user is another workbook, Excel can't find the "SaveAndClose " macro (I
don't recall the exact error message - something like "unable to locate macro
"SaveAndClose". I do the same thing at home and it works fine. Any ideas on
what could be causing this? The macro is shown below and is in the
"ThisWorkbook" code. The SaveAndClose macro is in a general module. Thanks.

Private Sub Workbook_Open()
On Error Resume Next
Application.OnTime RunWhen, "SaveAndClose", , False
On Error GoTo 0
RunWhen = Now + TimeSerial(0, NUM_MINUTES, 0)
Application.OnTime RunWhen, "SaveAndClose", , True
End Sub

Private Sub Workbook_BeforeClose(Cancel As Boolean)
On Error Resume Next
Application.OnTime RunWhen, "SaveAndClose", , False
On Error GoTo 0
End Sub

Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
On Error Resume Next
Application.OnTime RunWhen, "SaveAndClose", , False
On Error GoTo 0
RunWhen = Now + TimeSerial(0, NUM_MINUTES, 0)
Application.OnTime RunWhen, "SaveAndClose", , True
End Sub

Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, _
ByVal Target As Range)

On Error Resume Next
Application.OnTime RunWhen, "SaveAndClose", , False
On Error GoTo 0
RunWhen = Now + TimeSerial(0, NUM_MINUTES, 0)
Application.OnTime RunWhen, "SaveAndClose", , True

End Sub



All times are GMT +1. The time now is 05:55 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com