cancel
Showing results for 
Search instead for 
Did you mean: 

IF & Else Statement for VBA script

Former Member
0 Kudos

Hi every Experts!

I am looking some VBA script for my search results.

I am searching a value ;

     .findById("wnd[0]").maximize

     .findById("wnd[0]").sendVKey 71

     .findById("wnd[1]/usr/txtRSYSF-STRING").Text = "6306"

     .findById("wnd[1]/usr/txtRSYSF-STRING").caretPosition = 6

     .findById("wnd[1]").sendVKey 0

If the search results that I found then this code will copy and paste into my excel ;

    .findById("wnd[2]/usr/lbl[5,2]").SetFocus

    .findById("wnd[2]/usr/lbl[5,2]").caretPosition = 2

    .findById("wnd[2]/usr/lbl[48,2]").SetFocus

    .findById("wnd[2]/usr/lbl[48,2]").caretPosition = 6

     Sheet2.Cells(22, 4) = .findById("wnd[2]/usr/lbl[5,2]").Text

     Sheet2.Cells(22, 5) = .findById("wnd[2]/usr/lbl[48,2]").Text

    .findById("wnd[1]").sendVKey 0

    .findById("wnd[2]/tbar[0]/btn[17]").press

    .findById("wnd[1]/tbar[0]/btn[12]").press

But If I don’t have any search results then it’s says "Search unsuccessful - no hits found for: 6306" ;

     .findById("wnd[2]/usr/txtMESSTXT1").caretPosition = 4

     .findById("wnd[2]/tbar[0]/btn[0]").press

     .findById("wnd[1]/tbar[0]/btn[12]").press

Is there any way I can do If and else function? Or I can do another statement? (IF or Else) or argument ? something like that , I want combine this all together.

Thanks all,

Accepted Solutions (1)

Accepted Solutions (1)

script_man
Active Contributor
0 Kudos

Hi Raw,

you can try e.g. the following:

     .findById("wnd[0]").maximize

     .findById("wnd[0]").sendVKey 71

     .findById("wnd[1]/usr/txtRSYSF-STRING").Text = "6306"

     .findById("wnd[1]/usr/txtRSYSF-STRING").caretPosition = 6

     .findById("wnd[1]").sendVKey 0

     Information = ""

     on error resume next

     Information =  .findById("wnd[2]").Text

     on error goto 0

     if Information <> "Information" then

If the search results that I found then this code will copy and paste into my excel ;

    .findById("wnd[2]/usr/lbl[5,2]").SetFocus

    .findById("wnd[2]/usr/lbl[5,2]").caretPosition = 2

    .findById("wnd[2]/usr/lbl[48,2]").SetFocus

    .findById("wnd[2]/usr/lbl[48,2]").caretPosition = 6

     Sheet2.Cells(22, 4) = .findById("wnd[2]/usr/lbl[5,2]").Text

     Sheet2.Cells(22, 5) = .findById("wnd[2]/usr/lbl[48,2]").Text

    .findById("wnd[1]").sendVKey 0

    .findById("wnd[2]/tbar[0]/btn[17]").press

    .findById("wnd[1]/tbar[0]/btn[12]").press

     else

But If I don’t have any search results then it’s says "Search unsuccessful - no hits found for: 6306" ;

     .findById("wnd[2]/usr/txtMESSTXT1").caretPosition = 4

     .findById("wnd[2]/tbar[0]/btn[0]").press

     .findById("wnd[1]/tbar[0]/btn[12]").press

      end if

Regards,

ScriptMan

Former Member
0 Kudos

OMG ...You are the real Script Man , It is working !!!!


I just added Dim Information As String

Thank you my friend. Sincerely and truly, I appreciate you so much…

Answers (0)