Skip to Content
0
Aug 01, 2022 at 10:05 AM

extract data from SAP to excel VBA

649 Views

Hi , I have encounter the coding issue which cannot run even i have followed the similar code to extract the the data from SAP, any expert here could help me to have a look on the issue.

Public SapGuiAuto, WScript, msgco1

Public objGui As GuiApplication

Public objConn As GuiConnection

Public Session As GuiSession

Public objSbar As GuiStatusbar

Public objsheet As Worksheet

Sub OpenFK03()

Set SapGuiAuto = GetObject("SAPGUI")

Set objGui = SapGuiAuto.GetScriptingEngine

Set objConn = objGui.Children(0)

Set Session = objConn.Children(0)

Dim sh As Worksheet

Set sh = ThisWorkbook.Sheets("Status Checking")

Dim VendorCode As String

Dim COcode As String

Dim Value As String

Dim L As Integer

Dim lastrow As Integer

lastrow = Application.CountA(sh.Range("A:A"))

For L = 2 To lastrow

VendorCode = sh.Cells(L, 1)

COcode = sh.Cells(L, 2)

Value = sh.Cells(L, 3)

Session.FindById("wnd[0]").maximize

Session.FindById("wnd[0]/tbar[0]/okcd").Text = "FK03"

Session.FindById("wnd[0]").sendVKey 0

Session.FindById("wnd[0]/usr/ctxtRF02K-LIFNR").Text = VendorCode

Session.FindById("wnd[0]/usr/ctxtRF02K-BUKRS").Text = COcode

Session.FindById("wnd[0]/usr/ctxtRF02K-BUKRS").SetFocus

Session.FindById("wnd[0]/usr/ctxtRF02K-BUKRS").caretPosition = 4

Session.FindById("wnd[0]").sendVKey 0

Session.FindById("wnd[0]/mbar/menu[3]/menu[4]").Select

'session.FindById("wnd[0]/usr/txtRF02K-CONFSA_T").SetFocus

Value = Session.FindById("wnd[0]/usr/txtRF02K-CONFSA_T").Text

Session.FindById("wnd[0]/usr/txtRF02K-CONFSA_T").caretPosition = 9

Session.FindById("wnd[0]").sendVKey 0

Session.FindById("wnd[0]/tbar[0]/btn[3]").Press

Session.FindById("wnd[0]/tbar[0]/btn[3]").Press

Session.FindById("wnd[0]/tbar[0]/btn[3]").Press

Next L

End Sub