Results 1 to 16 of 16

VBA Sleep code time interval question

Threaded View

  1. #1
    Forum Contributor
    Join Date
    05-12-2021
    Location
    USA
    MS-Off Ver
    Microsoft Office 365
    Posts
    259

    VBA Sleep code time interval question

    Hello, I found some code on a site that can function similar to the codeline: Application.Wait (Now + TimeValue("0:00:01"))

    The code is:

    #If VBA7 Then
    
        Public Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As LongPtr) 'For 64-Bit versions of Excel
    
    #Else
    
        Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long) 'For 32-Bit versions of Excel
    
    #End If
    
    Sub SleepDemo()
    
    Sleep 500 'milliseconds (pause for 0.5 second)
    
    'resume macro
    
    End Sub
    Currently, I have an event code that changes a shapes color if data is entered in a particular cell. Unfortunately though, it can only do 1 second intervals with the application.Wait codeline. The code I have doing this is as follows:

    Private Sub Worksheet_Change(ByVal Target As Range)
        If Intersect(Target, Range("J34")) Is Nothing Then Exit Sub
        MsgBox "REMINDER: After filling out info for this row, click the Archive and Reset Sheet button", vbOKOnly
        Shapes("Archive_Reset").Fill.ForeColor.RGB = vbRed
        Application.Wait (Now + TimeValue("0:00:01"))
        Shapes("Archive_Reset").Fill.ForeColor.RGB = vbBlue
        Application.Wait (Now + TimeValue("0:00:01"))
        
    End Sub
    Is it possible to somehow use the sleep 500 in my event code to do the half second intervals to replace the applicaton.wait aspect? How might this be done if so?

    Thank you for your time!
    Last edited by PitchNinja; 09-11-2024 at 12:51 PM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Check if the in and out time falls between a specific time interval
    By srivibish in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 03-27-2020, 03:18 AM
  2. Sleep command question
    By Joven76 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-08-2018, 08:21 PM
  3. VBA calculate sleep time, when time is entered in military time format
    By axm1955 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 09-29-2017, 10:28 AM
  4. Replies: 11
    Last Post: 10-24-2016, 08:12 PM
  5. [SOLVED] VBA code to find if station is booked in certain date and time interval
    By sysss in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-23-2016, 06:24 PM
  6. Replies: 1
    Last Post: 04-29-2014, 04:42 AM
  7. Replies: 0
    Last Post: 04-23-2012, 10:06 AM

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