cancel
Showing results for 
Search instead for 
Did you mean: 

VBA Script FBL1N

kirana71
Newcomer

Accepted Solutions (0)

Answers (1)

Answers (1)

script_man
Active Contributor
0 Kudos

Hi Kirana Rania,

for example, if the data in Excel looks like the one above, you could test the following:
Sub Export()
'If Not IsObject(Application1) Then
Set SapGuiAuto = GetObject("SAPGUI")
Set Application1 = SapGuiAuto.GetScriptingEngine
'End If
'If Not IsObject(Connection) Then
Set Connection = Application1.Children(0)
'End If
'If Not IsObject(session) Then
Set session = Connection.Children(0)
'End If '


Dim LastRow
Dim sht As Worksheet

Set sht = ThisWorkbook.Worksheets("sheet1")

LastRow = sht.Range("C2").CurrentRegion.Rows.Count
'sht.Range("C2:C" & LastRow).Copy

sht.Range("B2").Select

For i = 1 To 3

Application.ActiveCell.Offset(0, 1).Range("A1").Select
sht.Range(Selection, Selection.End(xlDown)).Select
Application.Selection.Copy

session.findById("wnd[0]/tbar[0]/okcd").Text = "/NFBL1N"
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/usr/ctxtKD_BUKRS-LOW").Text = "BK01"
'session.findById("wnd[0]/usr/ctxtKD_BUKRS-LOW").SetFocus
'session.findById("wnd[0]/usr/ctxtKD_BUKRS-LOW").caretPosition = 4

session.findById("wnd[0]/usr/ctxtKD_LIFNR-LOW").Text = ""

session.findById("wnd[0]/usr/btn%_KD_LIFNR_%_APP_%-VALU_PUSH").press
session.findById("wnd[1]/tbar[0]/btn[24]").press
session.findById("wnd[1]/tbar[0]/btn[8]").press
session.findById("wnd[0]/tbar[1]/btn[8]").press
session.findById("wnd[0]/mbar/menu[0]/menu[3]/menu[1]").Select
session.findById("wnd[1]/usr/cmbG_LISTBOX").SetFocus
session.findById("wnd[1]/tbar[0]/btn[0]").press
session.findById("wnd[1]/usr/ctxtDY_PATH").Text = "D:\SAP\Data\"
session.findById("wnd[1]/usr/ctxtDY_FILENAME").Text = sht.Range("A" & CStr(i)).Value
'session.findById("wnd[1]/usr/ctxtDY_FILENAME").caretPosition = 36
session.findById("wnd[1]/tbar[0]/btn[11]").press
Application.Wait (Now + TimeValue("0:00:05"))
Next i

sht.Range("A1").Select
Application.CutCopyMode = False

session.findById("wnd[0]/tbar[0]/btn[3]").press

End Sub

Regards, ScriptMan