AppActivate Works Only Half the Time

Drogan

New Member
Joined
Mar 1, 2011
Messages
32
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.
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Hello Drogan,

What type of application is "FreeWatch"?

Sincerely,
Leith Ross
 
Upvote 0

Forum statistics

Threads
1,214,892
Messages
6,122,112
Members
449,066
Latest member
Andyg666

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top