Hi,
Can someone please help with this.
I don't understand why this bit of VBA is not working as expected.
It should wait until a Notepad window is opened (asynchronously by the user) before continuing.
If a Notepad window is opened BEFORE I execute the code it behaves as expected, but if the Notepad is only opened WHILE the code is executing it does not (it stays in the loop, with eno=5)
Thanks
Rob
Can someone please help with this.
I don't understand why this bit of VBA is not working as expected.
It should wait until a Notepad window is opened (asynchronously by the user) before continuing.
If a Notepad window is opened BEFORE I execute the code it behaves as expected, but if the Notepad is only opened WHILE the code is executing it does not (it stays in the loop, with eno=5)
Code:
Public Declare Sub sleep Lib "kernel32" Alias "Sleep" (ByVal dwMilliseconds As Long)
Sub gogo()
Dim eno As Integer
'wait until Notepad window is activated (asynchronously by user)
On Error Resume Next
Do
sleep 1000
AppActivate "Untitled - Notepad"
eno = Err.Number
MsgBox "Err.Number = " & eno
Loop Until eno = 0
MsgBox "Notepad is active"
' do things with SendKey
:
:
:
End Sub
Thanks
Rob