+ Reply to Thread
Results 1 to 7 of 7

The midnight hour

  1. #1
    Registered User
    Join Date
    07-20-2007
    Location
    Glasgow
    Posts
    7

    The midnight hour

    Hi!
    I'm using Excel to constantly run a macro with an "If" command to end the macro when a "switch" cell is equal to 0. Every X seconds values from a DDE link are coppied and pasted to a new location to create a record which can be viewed on a chart. After X "records" are created the file is "Archived" to a new sheet. This is working fine for me except for one issue...if the macro is left running as the system clock goes by midnight, the macro stops running.

    I don't have any code that uses time, other than to insert the current time and date into a cell as part of each "record". Any idea what could be causing this, or how to get round this?

    Cheers
    PhilT

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678
    Is the macro scheduled, or does it run in a loop? What sets the switch cell to zero?

  3. #3
    Registered User
    Join Date
    07-20-2007
    Location
    Glasgow
    Posts
    7
    Hi shg!
    I've worked out that it's my use of the "Timer" variable in Excel. I'm using a Do While loop to pause the macro. The loop compares the dynamic value of "Timer" against a snapshot of "Timer" + a variable used to select the refresh rate of my recorder.

    If someone can tell me the maximum value of "Timer" before it resets to 0, I can look for an invalid comparison value for "Timer" and solve my problem.

    Anyone have details on the "Timer" function?

    Cheers,
    PhilT

  4. #4
    Registered User
    Join Date
    07-20-2007
    Location
    Glasgow
    Posts
    7
    Hi shg!
    I've worked out that it's my use of the "Timer" variable in Excel. I'm using a Do While loop to pause the macro. The loop compares the dynamic value of "Timer" against a snapshot of "Timer" + a variable used to select the refresh rate of my recorder.

    If someone can tell me the maximum value of "Timer" before it resets to 0, I can look for an invalid comparison value for "Timer" and solve my problem.

    Anyone have details on the "Timer" function?

    Cheers,
    PhilT

  5. #5
    Registered User
    Join Date
    07-20-2007
    Location
    Glasgow
    Posts
    7
    VBA help provided the answer! Max value of "Timer" is 86400, which is number of seconds expired since the previous midnight!

  6. #6
    Registered User
    Join Date
    03-27-2013
    Location
    New Zealand
    MS-Off Ver
    Excel 2010
    Posts
    2

    Re: The midnight hour

    How did you get your macro to run through midnight? I am using the following code which also stops the macro at midnight.

    PauseTime = 3 ' Set duration.
    Start = Timer ' Set start time.
    Do While Timer < Start + PauseTime
    DoEvents ' Yield to other processes.
    Loop
    Finish = Timer ' Set end time.
    TotalTime = Finish - Start ' Calculate total time.

  7. #7
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: The midnight hour

    Undeze,

    This is a 5 yr old thread and not likely to get a response.

    Its better if you start your own thread. You can link back to this thread if required.
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1