• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Run Time Error '1004':

JAMIR

Member
Hi,

I have added runing clock in my workbook.

Global clockOn As Boolean
Sub runClock()
Range("GatePass!L5").Value = Now()
If clockOn = True Then
Application.OnTime Now + TimeValue("00:00:01"), "runClock"
End If
End Sub
Sub startClock()
clockOn = True
runClock
End Sub
Sub stopClock()
clockOn = False
End Sub

My Clock is runing very fine only ., but only that workbook open. If i open 2nd excel file it gives
Run Time Error '1004':
Method range of object _Global failed.

I can not open 2nd excel file while those workbook open. If End clock stop working or if Debug it gives
Range("GatePass!L5").Value = Now()

What should i do?

Zameer Shaikh
 
Hi Zameer ,

Using a fully qualified reference seems to work. Try this code :
Code:
Global clockOn As Boolean
 
Sub runClock()
    Range("[Hours.xls]GatePass!L5").Value = Now()
    If clockOn = True Then
      Application.OnTime Now + TimeValue("00:00:01"), "Hours.xls!runClock"
    End If
End Sub
 
Sub startClock()
    clockOn = True
    runClock
End Sub
 
Sub stopClock()
    clockOn = False
End Sub
Narayan
 
Hello Nayaran Sir,

I used above code, but it gives Compile error.
Constant, fixed length string, array, user-defined types and Declare statements not allowed as public member of object module..

My Workbook name is SIMS.xlsm

Regards,

Zameer Shaikh
 
Hello Narayan Sir,

Sorry I have add above code in the Gatepass sheet!. I am week in VBA that y it happend.

Thats y its give error and i did not change Wookbook name as SIMS on Hours.


But there is once little problem, i can able to open 2nd excel file. but if close SIMS.xlsm during open two file, SIMS.xlsm file open automatically. for example SIMS.xlsm & Hours.xls files open and if i want to close SIMS.xlsm file it open automatically. And if i close Hours.xls file then SIMS.xlsm closed.

Afterall it works fine. Thanks a lot sir. You rock sir.

Warmally Regards,

ZAMEER SHAIKH
 
Hi, JAMIR!
Put the code into a standard module and not into a object (either workbook or worksheet) class module.
Regards!
 
But there is once little problem, i can able to open 2nd excel file. but if close SIMS.xlsm during open two file, SIMS.xlsm file open automatically. for example SIMS.xlsm & Hours.xls files open and if i want to close SIMS.xlsm file it open automatically. And if i close Hours.xls file then SIMS.xlsm closed.
Hi Zameer ,

Can you explain the problem in a little more detail ? Or can you upload your file which has the timer code ?

Narayan
 
Hi, JAMIR!
Just in case...
This:
Put the code into a standard module and not into a object (either workbook or worksheet) class module.
was for this:
I used above code, but it gives Compile error.
Constant, fixed length string, array, user-defined types and Declare statements not allowed as public member of object module..
Regards!
 
Back
Top