Ade
Ade

Reputation: 1

Replace customer ID with VBA variable in FindById() function?

I am trying to automate some of my SAP work with VBA. I am stuck in the sign in as the script to customer price file is

session.FindById("wnd[1]/usr/cntlPRM_CC3000_1/shellcont/shell").SapEvent "Frame0", "sapbu_cl= &sapse_cl= &sapin_cl=S1F1E6~L&evtcode=ENTR&scroll_pos=0&S1F1E1L=2000&S1F1E2L=10&S1F1E3L=**98701**&S1F1E4L=&S1F1E4H=&S1F1E5L=&S1F1E5H=&S1F1E6L=12.10.2022", "sapevent:S1F1" 

This is working well for the individual customer ID but I would like to loop through all the customers with different ID's specified in (Sheet 1, starting from A2). Therefore in this script I would need to use variable to replace the customer ID 98701. I found an instruction of using Cvar(Customer). However it leaves the Customer cell empty.

The code is below:

Dim i As Integer
Dim Customer As String

i = 2

Do Until IsEmpty(Cells(i, 1))

  Customer = Range("A" & i)

  On Error Resume Next

  ...
  session.FindById("wnd[1]/usr/cntlPRM_CC3000_1/shellcont/shell").SapEvent "Frame0", _
    "sapbu_cl= &sapse_cl= &sapin_cl=S1F1E6~L&evtcode=ENTR&scroll_pos=0&S1F1E1L=2000" _
    & "&S1F1E2L=10&S1F1E3L=Cvar(Customer)&S1F1E4L=&S1F1E4H=" _
    & "&S1F1E5L=&S1F1E5H=&S1F1E6L=12.10.2022", _
    "sapevent:S1F1" 
  ...

  i = i + 1
Loop

Session.FindById(...) seems to be string and I cannot include variant as a value to it.

The cell has a field name as well to write or point out directly.

SAP field ID

However I cannot find instructions on how to point to the certain field name directly in this case or include the variant to the Session.FindById string. Other solutions are welcome also!

Upvotes: 0

Views: 238

Answers (1)

Storax
Storax

Reputation: 12167

You should use CStr instead and concatenate the strings correctly

session.FindById("wnd[1]/usr/cntlPRM_CC3000_1/shellcont/shell").SapEvent "Frame0", _
    "sapbu_cl= &sapse_cl= &sapin_cl=S1F1E6~L&evtcode=ENTR&scroll_pos=0&S1F1E1L=2000" _
    & "&S1F1E2L=10&S1F1E3L=" & CStr(Customer) & " S1F1E4L=&S1F1E4H=" _
    & "&S1F1E5L=&S1F1E5H=&S1F1E6L=12.10.2022", _
    "sapevent:S1F1"

Maybe the following links shed light on the topic string concatenation

How can I concatenate strings in VBA?

Concatenating strings containing " and & characters

Upvotes: 1

Related Questions