Infinite Loop crashes VBA/Powershell and Win11

Viewed 27

How can I create a Powershell or VBA script to run a command, wait and loop the command and wait infinitely until I close the respective window? I have tried the below in Powershell and VBA but they make the respective Powershell or VBA windows unresponsive and a bit later the whole system becomes unresponsive and I have to reboot.

Sub proc()
Do while $true
Application.Windows("workbook1.xls").Activate
Application.Wait(Now + TimeValue("0:10:00"))
Loop
End Sub

UPDATE:

  1. I think it's obvious what I am trying to do: activate the window of a particular workbook every few seconds indefinitely.
  2. I have tried DoEvents (both below the Application.Windows and the Application.Wait but it does not solve anything. Also I saw the below which says to avoid DoEvents: https://www.fmsinc.com/microsoftaccess/modules/examples/AvoidDoEvents.asp
  3. I tried Application.OnTime which made things much better but eventually got unresponsiveness too
0 Answers
Related