0

I'm currently trying to run a macro around five times per second using the Application.OnTime but it doesn't work with times less than a second. I know excel can handle my macro that many times as I've assigned it to a key and held it down. So is there any other way I can run my macro multiple times per second?

Thanks a lot.

1 Answers1

0
Interval = 0.2
CurrentTime = Timer

Do While True
    If Timer > CurrentTime + Interval Then

        'Write your code here.
        
        Current = Timer
    End If
    DoEvents
Loop
pullidea-dev
  • 1,768
  • 1
  • 7
  • 23
  • Thanks! This does run the code multiple times per seconds but other macros I call through inputs don't seem to run. Any ideas? – Jack Jamison May 24 '21 at 04:21
  • ` Private Sub Workbook_Open() Application.OnKey "{LEFT}", "LeftMod" Application.OnKey "{RIGHT}", "RightMod" Application.OnKey Chr(32), "SpaceMod" End Sub ` ` Sub Loop() Interval = 0.2 CurrentTime = Timer Do While True If Timer > CurrentTime + Interval Then hasMoved = False Current = Timer End If DoEvents Loop End Sub ` – Jack Jamison May 24 '21 at 04:37
  • So you have 3 functions like as "RightMod", "LeftMod" and "SpaceMod"? Then you need to write my code in each function. And could you tick my answer? – pullidea-dev May 24 '21 at 04:39
  • I just ticked it but the issue is that I am running your code when the user clicks a button. I want those input functions to work alongside your code – Jack Jamison May 24 '21 at 04:42
  • Please explain in detail. – pullidea-dev May 24 '21 at 05:06
  • I run a macro with your code when the user clicks a button. I want your code to run throughout the rest of the time the user is interacting with my sheet, and it works. However, those inputs assigned to functions do not get called while your code is running. Hope this helps. – Jack Jamison May 24 '21 at 05:12
  • Can you share your file? – pullidea-dev May 24 '21 at 05:14
  • Here: https://wetransfer.com/downloads/10f77dd995a154534c63dc463a813b0720210524052730/9470a3 Thanks for the help! Sorry if what I'm trying to do is weird – Jack Jamison May 24 '21 at 05:28
  • I just realized I have an extra End Sub at the start of the file. I accidentally left it there while cleaning up. It isn't the issue so you can just remove it. – Jack Jamison May 24 '21 at 05:30