A family of Microsoft spreadsheet software with tools for analyzing, charting, and communicating data.
Sometimes it appears to works and sometimes not.
I pasted the code into its own module. In the "Keystroke" macro (in another module) I added "TurnNumLockOn" to the line after the Sendkeys statement >
Sub Keystroke()
For cnt = 1 To 10000
SendKeys "{home}"
TurnNumLockOn
Application.Wait (Now + TimeValue("0:10:00"))
Next
End Sub
Whether or not the focus stays on the Keystroke macro spreadsheet, the computer screen does not time out, so that part is working. But I still have a problem with the numlock sometimes turning off and sometimes turning on. Turning on is good, but why the inconsistency?
Note that the Keystroke macro spreadsheet does not always have the focus, since I might be actively using other apps, or might just be monitoring them. Heck, I have even purposely turned off the numlock, then started the macro, and it has sometimes turned it back on immediately and sometimes not.
Any ideas?
Try changing this line of code....
SendKeys "{home}"
to this....
SendKeys "{home}", True
That second optional argument will make the macro wait until the SendKeys operation has completed. I believe the "sometimes it appears to works and sometimes not" is probably due to a timing issue.... if I am right, then making the macro wait until SendKeys is done should fix the intermittent problem you are seeing.