Hi,
I’m having a problem with the following tract of VBA. It is intended that it should loop round until a window with a particular title (as held in string wtit) is detected. It works ok if the said window already exists before running the code, but it fails on the SECOND time round the loop if the window does not pre-exist.
I assume I’m doing something wrong in the error handling or error clearing but I cannot figure it out. Any suggestions on what I’m doing wrong, please?
Many Thanks
Rob
I’m having a problem with the following tract of VBA. It is intended that it should loop round until a window with a particular title (as held in string wtit) is detected. It works ok if the said window already exists before running the code, but it fails on the SECOND time round the loop if the window does not pre-exist.
I assume I’m doing something wrong in the error handling or error clearing but I cannot figure it out. Any suggestions on what I’m doing wrong, please?
Many Thanks
Rob
Code:
For appacttry = 1 To 3
On Error GoTo appactfail
AppActivate wtit ‘fails HERE on the second time round the loop
‘with message “Run-time error 5 – Invalid procedure call or argument
On Error GoTo 0
GoTo appactok
appactfail:
Err.clear
On Error GoTo 0
MsgBox "failed to find window on try number " & appacttry
Next appacttry
appactok:
Last edited by a moderator: