在下面的代码中,Sap选择了密钥22,但是对于其他用户,密钥是不同的,因此我无法使该代码对两个用户均有效。通过搜索文字可以找到钥匙吗?
Sub Report_140()
If Not IsObject(SAP) Then
Set SapGuiAuto = GetObject("SAPGUI")
Set SAP = SapGuiAuto.GetScriptingEngine
End If
If Not IsObject(Connection) Then
Set Connection = SAP.Children(0)
End If
If Not IsObject(session) Then
Set session = Connection.Children(0)
End If
If IsObject(WScript) Then
WScript.ConnectObject session, "on"
WScript.ConnectObject Application, "on"
End If
session.findById("wnd[0]").maximize
session.findById("wnd[0]/tbar[0]/okcd").Text = "S_Ph0_48000513"
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[1]/usr/cmbDYNP4100-DD_USERGROUP").SetFocus
session.findById("wnd[1]/usr/cmbDYNP4100-DD_USERGROUP").Key = "22"
答案 0 :(得分:0)
似乎您在组合框中搜索事务S_Ph0_48000513的用户组的某些文本。我为临时查询S_Ph0_48000513尝试了以下代码:
Const KEY_TEXT = "..your user group ..."
Dim k As Long
Dim keyFound As Boolean
With session
.findById("wnd[0]/tbar[0]/okcd").Text = "S_Ph0_48000513"
.findById("wnd[0]").sendVKey 0
k = 1
'Careful! If the KEY_TEXT is not found this loop will run into an error
Do
' Setting the key is slow but right now it seems there is no other way
.findById("wnd[1]/usr/cmbDYNP4100-DD_USERGROUP").Key = CStr(k)
keyFound = InStr(1, .findById("wnd[1]/usr/cmbDYNP4100-DD_USERGROUP").Text, KEY_TEXT)
k = k + 1
Loop Until keyFound
End With