Results 1 to 2 of 2
  1. #1
    talhaparvaiz@yahoo.com is offline Novice
    Windows 7 64bit Access 2013 64bit
    Join Date
    May 2020
    Posts
    29

    Automatically run the macro every minute between specific time


    Hello,
    I've developed an Excel file that dynamically updates via an API with real-time stock data. My objective is to automate the process of pushing this data to MS Access every minute.
    I've made progress on certain aspects of the task, but there are areas where I could benefit from expert guidance.
    Here's what's currently not functioning as desired:

    - The macro I've created needs to be executed manually. My goal is to automate this process so that it runs automatically every minute.

    - When running the macro manually, I encounter messages prompting confirmation for data insertion into certain tables. I aim to eliminate the need for manual confirmation


    - Additionally, I aim to restrict the execution of this macro to occur only between 8:30 AM and 3:00 PM Central Time.

    I've included the macro and the Excel file for your reference.
    Thank you for your assistance.
    Attached Files Attached Files

  2. #2
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    Insert a standard module (menu>insert>module). It should contain this:
    Code:
    Option Explicit
    Public alertTime As Variant
    
    Public Sub EventMacro()
    MsgBox "test"
    SetOnTime
    
    End Sub
    
    Sub SetOnTime()
    
    alertTime = Now + TimeSerial(0, 0, 10)
    Application.OnTime alertTime, "eventmacro"
    
    End Sub
    If you want workbook open event to trigger the code it should contain this:
    Code:
    Private Sub Workbook_Open()
    Dim alertTime As Double
    
    alertTime = Time + TimeSerial(0, 0, 10) 'this adds 10 sec. to time workbook opens for first run
    Application.OnTime alertTime, "EventMacro"
    
    End Sub
    A msgbox should open 10 secs after workbook open, then every 10 seconds. If you can get that to work then the next steps can be figured out.
    Note: you can do all the pasting, then paste this into the immediate window
    Application.OnTime alerttime, "eventmacro", , False

    You can then trigger the wb open even by putting your cursor at the beginning of the open event code and pressing F5. You should get the msgbox 10 seconds later.

    When you want to stop the event, put cursor at the end of that line in the immediate window and hit Enter.
    OR you can change the value from 10 secs to some other value if you want more time in between.

    EDIT - your file must be xlsm. Next time, please upload xlsm when you want code, because xls files cannot contain vba (macros).
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Hour Minute Format not time specific
    By jungmanish in forum Access
    Replies: 5
    Last Post: 05-06-2018, 03:46 AM
  2. Replies: 4
    Last Post: 04-04-2015, 03:28 AM
  3. Replies: 2
    Last Post: 01-16-2015, 04:22 PM
  4. Replies: 1
    Last Post: 01-13-2015, 01:33 PM
  5. Replies: 1
    Last Post: 02-22-2012, 04:59 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums