0

I need some help here, I have a command for SAP GUI script in VBA where I just need to change a number am each line, is there a way to have just one line and create a loop? num1 = 5, num2 = 9, num3 = 10

session.findById("wnd[1]/usr/chk[2,5]").Selected = True
session.findById("wnd[1]/usr/chk[2,9]").Selected = True
session.findById("wnd[1]/usr/chk[2,10]").Selected = True

what I hope

session.findById("wnd[1]/usr/chk[2,numX]").Selected = True
1
  • The question is only about concatenating string and numeric variable, it's not specific to SAP GUI. I have changed the title and tags accordingly. Commented Aug 3, 2022 at 18:05

2 Answers 2

2

Another way using a For Each loop.

Sub Test()

    Dim vNums() As Variant
    vNums = Array(5, 9, 10)
    
    Dim vNum As Variant
    For Each vNum In vNums
        session.findById("wnd[1]/usr/chk[2," & vNum & "]").Selected = True
    Next vNum
    
End Sub
Sign up to request clarification or add additional context in comments.

Comments

0

for example:

For numx = 5 To 13 Step 4
    If numx = 13 Then numx = 10
    session.findById("wnd[1]/usr/chk[2," & cstr(numx) & "]").Selected = True
next

Regards, ScriptMan

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.