使用 VBA 将单元格的值从 Excel 复制到 SAP GUI 中的单元格 [已关闭]

Copy the value of a cell from Excel to a cell in SAP GUI with VBA [closed]

提问人:Edu1243 提问时间:11/14/2023 最后编辑:Sandra RossiEdu1243 更新时间:11/14/2023 访问量:38

问:


想改进这个问题吗?通过编辑这篇文章添加详细信息并澄清问题。

2天前关闭。

我正在编写一个 VBA Excel 代码来初始化 SAP GUI 并创建制造订单,我希望宏获取用户输入的某些单元格值并将它们放置在 SAP ERP 中的相应空间中,但我收到错误。当宏必须获取单元格的值并将其放入 SAP 中的目标数量空间时,我得到

无法按 id 找到控件

我不知道这个错误有多普遍,我是尝试将SAP GUI与Excel连接的新手。如果您能帮助我,我将不胜感激。

这是我的代码:

Sub Ingresar_SAP(User As String, password As String)


Dim wb As Worksheet
Dim Appl As Object
Dim Connection As Object
Dim session As Object
Dim WshShell As Object
Dim SapGui As Object

Set wb = ThisWorkbook.Worksheets("Hoja2")

If FindProcess("saplogon.exe") Then
    Set SapGui = GetObject("SAPGUI")
Else
'Of course change for your file directory
    Shell "C:\Program Files (x86)\SAP\FrontEnd\SAPgui\saplogon.exe", 4
    Set WshShell = CreateObject("WScript.Shell")

    Do Until WshShell.AppActivate("SAP Logon ")
        Application.Wait Now + TimeValue("0:00:01")
    Loop
End If

Set WshShell = Nothing

Set SapGui = GetObject("SAPGUI")
Set Appl = SapGui.GetScriptingEngine
Set Connection = Appl.Openconnection("MQF Audi Mexico Finanz Test Link", _
    True)
Set session = Connection.Children(0)

''if You need to pass username and password
'session.findById("wnd[0]/usr/txtRSYST-MANDT").Text = "900"
'session.findById("wnd[0]/usr/txtRSYST-BNAME").Text = User
'session.findById("wnd[0]/usr/pwdRSYST-BCODE").Text = password
'session.findById("wnd[0]/usr/txtRSYST-LANGU").Text = "EN"

If session.Children.Count > 1 Then

    answer = MsgBox("You've got opened SAP already," & _
"please leave and try again", vbOKOnly, "Opened SAP")

    session.findById("wnd[1]/usr/radMULTI_LOGON_OPT3").Select
    session.findById("wnd[1]/usr/radMULTI_LOGON_OPT3").SetFocus
    session.findById("wnd[1]/tbar[0]/btn[0]").press

    Exit Sub

End If

session.findById("wnd[0]").maximize
session.findById("wnd[0]/tbar[0]/okcd").Text = "IW81"
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/usr/ctxtAUFPAR-PM_AUFART").Text = "zmp4"
session.findById("wnd[0]/usr/cmbCAUFVD-PRIOK").Key = "3"
session.findById("wnd[0]/usr/ctxtCAUFVD-MATNR").Text = wb.Cells(3, 2).Value
session.findById("wnd[0]/usr/ctxtCAUFVD-SERIALNR").Text = wb.Cells(4, 2).Value
session.findById("wnd[0]/usr/ctxtCAUFVD-IWERK").Text = "6300"
session.findById("wnd[0]/usr/ctxtCAUFVD-IWERK").SetFocus
session.findById("wnd[0]/usr/ctxtCAUFVD-IWERK").caretPosition = 4
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[1]").Close
session.findById("wnd[0]/usr/ctxtAUFPAR-PM_AUFART").Text = "zpm4"
session.findById("wnd[0]/usr/cmbCAUFVD-PRIOK").Key = "3"
session.findById("wnd[0]/usr/ctxtCAUFVD-MATNR").Text = "A9009642"
session.findById("wnd[0]/usr/ctxtCAUFVD-SERIALNR").Text = "10017903"
session.findById("wnd[0]/usr/ctxtCAUFVD-IWERK").Text = "6300"
session.findById("wnd[0]/usr/ctxtCAUFVD-IWERK").SetFocus
session.findById("wnd[0]/usr/ctxtCAUFVD-IWERK").caretPosition = 4
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/usr/cmbCAUFVD-PRIOK").Key = "4"
session.findById("wnd[0]/usr/ctxtCAUFVD-MATNR").Text = "A9009642"
session.findById("wnd[0]/usr/ctxtCAUFVD-SERIALNR").Text = "10017903"
session.findById("wnd[0]/usr/ctxtCAUFVD-SERIALNR").SetFocus
session.findById("wnd[0]/usr/ctxtCAUFVD-SERIALNR").caretPosition = 8
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/usr/subSUB_ALL:SAPLCOIH:3001/ssubSUB_LEVEL:SAPLCOIH:1100/subSUB_KOPF:SAPLCOIH:1102/txtCAUFVD-KTEXT").Text = "Reparación DOSIFICADOR L10011786"
session.findById("wnd[0]/usr/subSUB_ALL:SAPLCOIH:3001/ssubSUB_LEVEL:SAPLCOIH:1100/tabsTS_1100/tabpIHKZ/ssubSUB_AUFTRAG:SAPLCOIH:1126/txtCAUFVD-GAMNG").Text = wb.Range("B9").Value
session.findById("wnd[0]/usr/subSUB_ALL:SAPLCOIH:3001/ssubSUB_LEVEL:SAPLCOIH:1100/tabsTS_1100/tabpIHKZ/ssubSUB_AUFTRAG:SAPLCOIH:1126/ctxtRESBD-WERKS").Text = "6300"
session.findById("wnd[0]/usr/subSUB_ALL:SAPLCOIH:3001/ssubSUB_LEVEL:SAPLCOIH:1100/tabsTS_1100/tabpIHKZ/ssubSUB_AUFTRAG:SAPLCOIH:1126/ctxtRESBD-LGORT").Text = "A401"
session.findById("wnd[0]/usr/subSUB_ALL:SAPLCOIH:3001/ssubSUB_LEVEL:SAPLCOIH:1100/tabsTS_1100/tabpIHKZ/ssubSUB_AUFTRAG:SAPLCOIH:1126/ctxtMCHA-BWTAR").Text = "DEFECT"
session.findById("wnd[0]/usr/subSUB_ALL:SAPLCOIH:3001/ssubSUB_LEVEL:SAPLCOIH:1100/tabsTS_1100/tabpIHKZ/ssubSUB_AUFTRAG:SAPLCOIH:1126/ctxtAFPOD-PWERK").Text = "6300"
session.findById("wnd[0]/usr/subSUB_ALL:SAPLCOIH:3001/ssubSUB_LEVEL:SAPLCOIH:1100/tabsTS_1100/tabpIHKZ/ssubSUB_AUFTRAG:SAPLCOIH:1126/ctxtAFPOD-LGORT").Text = "A401"
session.findById("wnd[0]/usr/subSUB_ALL:SAPLCOIH:3001/ssubSUB_LEVEL:SAPLCOIH:1100/tabsTS_1100/tabpIHKZ/ssubSUB_AUFTRAG:SAPLCOIH:1126/ctxtAFPOD-BWTAR").Text = "USED"
session.findById("wnd[0]/usr/subSUB_ALL:SAPLCOIH:3001/ssubSUB_LEVEL:SAPLCOIH:1100/tabsTS_1100/tabpIHKZ/ssubSUB_AUFTRAG:SAPLCOIH:1126/subHEADER:SAPLCOIH:0154/ctxtCAUFVD-INGPR").Text = "CC7"
session.findById("wnd[0]/usr/subSUB_ALL:SAPLCOIH:3001/ssubSUB_LEVEL:SAPLCOIH:1100/tabsTS_1100/tabpIHKZ/ssubSUB_AUFTRAG:SAPLCOIH:1126/subHEADER:SAPLCOIH:0154/ctxtCAUFVD-VAPLZ").Text = "KBA40RM1"
session.findById("wnd[0]/usr/subSUB_ALL:SAPLCOIH:3001/ssubSUB_LEVEL:SAPLCOIH:1100/tabsTS_1100/tabpIHKZ/ssubSUB_AUFTRAG:SAPLCOIH:1126/ctxtAFPOD-BWTAR").SetFocus
session.findById("wnd[0]/usr/subSUB_ALL:SAPLCOIH:3001/ssubSUB_LEVEL:SAPLCOIH:1100/tabsTS_1100/tabpIHKZ/ssubSUB_AUFTRAG:SAPLCOIH:1126/ctxtAFPOD-BWTAR").caretPosition = 4
session.findById("wnd[0]/tbar[1]/btn[25]").press
session.findById("wnd[1]/usr/btnSPOP-VAROPTION1").press
session.findById("wnd[0]/tbar[0]/btn[11]").press
session.findById("wnd[1]").Close
session.findById("wnd[0]/tbar[0]/btn[11]").press
session.findById("wnd[1]/usr/btnSPOP-OPTION1").press


End Sub

Excel VBA SAP-GUI

评论

2赞 Sandra Rossi 11/14/2023
我的意思是你指示的身份证什么都没有。正如您通过搜索所看到的那样,此错误非常常见,并且 90% 的时间答案都是一样的。请参阅存在的屏幕字段。

答: 暂无答案