Skip to Content
0
Former Member
Sep 29, 2015 at 10:13 AM

Pull up data from excel and update it in SAP then Save.

153 Views

Hi All,

I am a fresher to this scripting world....Can someone help me correct the below VB scripting as it is throwing up an error as below...?

What i exactly wanted to do is that to set output for list of invoice numbers in VF02 t-code in SAP and save it. I want this task to run on all the below invoices one by one after it is saved. Also the below list of invoice numbers are saved in"Book 2" as per below path.

C:\Users\mohank\Desktop\Book2.xlsx

My code is as below:-

***************************************************************************************************************************************************************************

If Not IsObject(application) Then

Set SapGuiAuto = GetObject("SAPGUI")

Set application = SapGuiAuto.GetScriptingEngine

End If

If Not IsObject(connection) Then

Set connection = application.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 = "/nvf02"

session.findById("wnd[0]").sendVKey 0

Set xclapp = GetObject(, "Excel.Application")

Set xclwbk = xclapp.Workbooks.Open("C:\Users\mohank\Desktop\Book2.xlsx")

Set xclsht = xclwbk.Sheets("Sheet1")

If Not IsObject(application) Then

for i = 2 to xclapp.ActiveCell.SpecialCells(11).Row

for j = 1 to xclapp.ActiveCell.SpecialCells(11).Column

if j=1 then Transaction = xclsht.Cells(i,j).Value

next

session.findById("wnd[0]/usr/ctxtVBRK-VBELN").text = Transaction

session.findById("wnd[0]/usr/ctxtVBRK-VBELN").caretPosition = 10

session.findById("wnd[0]").sendVKey 0

session.findById("wnd[0]/mbar/menu[2]/menu[0]/menu[3]").select

session.findById("wnd[0]/usr/tblSAPDV70ATC_NAST3/ctxtDNAST-KSCHL[1,0]").text = "ZB17"

session.findById("wnd[0]/usr/tblSAPDV70ATC_NAST3/ctxtDNAST-KSCHL[1,0]").caretPosition = 4

session.findById("wnd[0]").sendVKey 0

session.findById("wnd[0]/usr/tblSAPDV70ATC_NAST3").getAbsoluteRow(0).selected = true

session.findById("wnd[0]").sendVKey 2

session.findById("wnd[0]/usr/ctxtNAST-LDEST").text = "in03"

session.findById("wnd[0]/usr/ctxtNAST-LDEST").caretPosition = 4

session.findById("wnd[0]").sendVKey 0

session.findById("wnd[0]").sendVKey 3

session.findById("wnd[0]/usr/tblSAPDV70ATC_NAST3").getAbsoluteRow(0).selected = true

session.findById("wnd[0]").sendVKey 11

next

msgbox "All " & cstr(xclapp.ActiveCell.SpecialCells(11).Row - 1) & " Excel rows have been processed."

Set xclwbk = Nothing

Set xclsht = Nothing

xclapp.Quit

set xclapp = Nothing

***************************************************************************************************************************************************************************

Please help..thanks:)

Attachments

Capture.JPG (15.3 kB)
Error Message.JPG (24.0 kB)