So I've created an Excel workbook to start and stop an external stopwatch and automatically copy the time to Excel, and everything works perfectly except the Stop function. Half the time it activates and the other half it doesn't. I used the ALT+TAB VBA SendKeys command which works fine, but only IF the stopwatch is the next immediately active window, but even then there is an occasional rare instance that it doesn't work. What I want is for the stopwatch to be activated by the AppActivate command just in case the user has switched windows and ALT+TAB won't work. Here's the code I have:
Code1:
Sub StopTimer()
AppActivate "FreeWatch"
SendKeys "{ENTER}", True
AppActivate "Microsoft Excel"
ActiveSheet.Paste
End Sub
Code2:
Sub StopTimer()
SendKeys "%{TAB}", True
SendKeys "{ENTER}", True
AppActivate "Microsoft Excel"
ActiveSheet.Paste
End Sub
In the first code, I even attemped to use the wait function (Application.Wait...), but it takes too long. In the second code, with SendKeys, it works most of the time, but there is an extremely rare occasion that it doesn't activate the next window (being the timer) as stated above.
As the AppActivate only works about half the time it doesn't catch the STOP function on the stopwatch so it doesn't copy the time. I have to hit the Stop button I've created in Excel sometimes 3 or more times for it to properly work. The delay event takes too long as it needs to be almost instant, not up to a 1 second delay. If anyone has any clue how I can get this to work without using a delay or using the ALT+TAB functions (or using an API script as I've recently read about), that would be great.
Code1:
Sub StopTimer()
AppActivate "FreeWatch"
SendKeys "{ENTER}", True
AppActivate "Microsoft Excel"
ActiveSheet.Paste
End Sub
Code2:
Sub StopTimer()
SendKeys "%{TAB}", True
SendKeys "{ENTER}", True
AppActivate "Microsoft Excel"
ActiveSheet.Paste
End Sub
In the first code, I even attemped to use the wait function (Application.Wait...), but it takes too long. In the second code, with SendKeys, it works most of the time, but there is an extremely rare occasion that it doesn't activate the next window (being the timer) as stated above.
As the AppActivate only works about half the time it doesn't catch the STOP function on the stopwatch so it doesn't copy the time. I have to hit the Stop button I've created in Excel sometimes 3 or more times for it to properly work. The delay event takes too long as it needs to be almost instant, not up to a 1 second delay. If anyone has any clue how I can get this to work without using a delay or using the ALT+TAB functions (or using an API script as I've recently read about), that would be great.