เรียน อาจารย์ ครับ
ผมได้บันทึก script ที่ระบบ Sap และนำ code มาใส่ใน excel VBA ความต้องการคือ เรียก transection vl02n ของ Sap
จากนั้นให้นำค่าใน sheet ตั้งแต่ cell A2 ไปใส่ใน Sap แล้วกด post และกลับมานำค่า cell A3 มาทำเช่นเดิม วนไปจนครบทุกบรรทัด
ที่มีในคอลัมภ์ A ทดลองที่เครื่องผมเป็น Excel 2013 งสามารถใช้งานได้ตามที่ต้องการ แต่เครื่อง user อื่น เป็น excel 2010 พบปัญหาใช้งานไม่ได้
แสดง error 619 The control could not be found by id ไฮ้ไลท์สีเหลือง อยู่ที่บรรทัด session.findById("wnd[0]/usr/ctxtLIKP-VBELN").Text = Cells(i, 1)
ขอปรึกษาว่าจะต้องแก้ไข code อย่างไรให้สามารถใช้งานได้เช่นกันครับ ขอบคุณมากครับ
Code: Select all
Public Sub SimpleSAPVL02N()
Set SapGuiAuto = GetObject("SAPGUI") 'Get the SAP GUI Scripting object
Set SAPApp = SapGuiAuto.GetScriptingEngine 'Get the currently running SAP GUI
Set SAPCon = SAPApp.Children(0) 'Get the first system that is currently connected
Set session = SAPCon.Children(0) 'Get the first session (window) on that connection
Dim LR As Long
Dim i As Integer
LR = Range("A" & Rows.Count).End(xlUp).Row
i = 2
For i = 2 To LR
'Move sloc
session.findById("wnd[0]").maximize
session.findById("wnd[0]/tbar[0]/okcd").Text = "/nvl02n"
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/usr/ctxtLIKP-VBELN").Text = Cells(i, 1)
session.findById("wnd[0]/usr/ctxtLIKP-VBELN").caretPosition = 10
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/tbar[1]/btn[20]").press
'for loop
Next i
End Sub