VBA - 'Object required' error message

Dear Experts,

Could you please have a look this short code part, briefly its target is assigning a button text (from SAP application) to a variable, but if there is no such button then going further:

ErrMes = session.findById("wnd[2]/usr/txtMESSTXT1").Text
Debug.Print ErrMes
If ErrMes Is Nothing Then
    GoTo NoChangeMessage
Else
    ErrMes = session.findById("wnd[2]/usr/txtMESSTXT1").Text
    If InStr(1, ErrMes, "change", vbTextCompare) > 0 Then
    session.findById("wnd[2]/tbar[0]/btn[0]").press
    End If
End If

Open in new window


Actually it has the issue that the ErrMes variable got a value (as Debug.Print shows 'No changes were made' text assigned to it from the button), but then the VBA script stops at line

If ErrMes Is Nothing Then

Open in new window

with error message:

Run-time error '424'
Object required


Could you please advise what is the nature of the issue there and eventually how to eliminate?

Thanks in advance,
LVL 1
csehzIT consultantAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
That's because as per the code ErrMes should be a string variable and you cannot treat it as an object variable.
Instead of checking
If ErrMes Is Nothing Then

Open in new window

Check it like
If ErrMes = "" Then

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
csehzIT consultantAuthor Commented:
Neeraj thanks that works and I am so glad that hopefully successfully assigned to you that 1000 point at last (as missed it already in two questions before)
1
Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
You're welcome!
Don't worry, that's completely fine. :)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VBA

From novice to tech pro — start learning today.