Search code examples
vbastring-concatenationsap-gui

Concatenating a string and numeric variable


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

Solution

  • 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