Thread: Code Stopped
View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
LiAD LiAD is offline
external usenet poster
 
Posts: 386
Default Code Stopped

Hi,

I was given a code which has been working ok until recently, at least as far
as I know but its just stopped working and I dont know why. Nothing has been
altered in the file.

The following section of code shows up as;

Run time error '1004'
Method 'OnTime' of object '_Application' failed

Would anyone know what the issue could be?

VB shows the following line as the issue;
Application.OnTime RunWhen, "SaveAndClose", , False

which is contained with this part of a code
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim oCB As CommandBar
On Error Resume Next
Application.OnTime RunWhen, "SaveAndClose", , False
On Error GoTo 0
For Each oCB In Application.CommandBars
oCB.Enabled = True
Next oCB

Application.DisplayFormulaBar = mFormulaBar

Application.Quit
End Sub

The complete code is

Private mFormulaBar

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim oCB As CommandBar
On Error Resume Next
Application.OnTime RunWhen, "SaveAndClose", , False
On Error GoTo 0
For Each oCB In Application.CommandBars
oCB.Enabled = True
Next oCB

Application.DisplayFormulaBar = mFormulaBar

Application.Quit
End Sub

Private Sub Workbook_Open()
Dim oCB As CommandBar
On Error Resume Next
Application.OnTime RunWhen, "SaveAndClose", , False
On Error GoTo 0

Application.OnKey "%{F11}", "dummy"

For Each oCB In Application.CommandBars
oCB.Enabled = False
Next oCB

mFormulaBar = Application.DisplayFormulaBar
Application.DisplayFormulaBar = False

RunWhen = Now + TimeSerial(0, NUM_MINUTES, 0)
Application.OnTime RunWhen, "SaveAndClose", , True
End Sub