Skip to Content
0
Jan 20, 2020 at 12:16 PM

Create SAP invoice using excel macro

167 Views

Hi , I'm new to Excel Macro and tried to do automation in SAP GUI.

I need help to do copy sales order number in to GSAP.

Currently i'm using Range("D3") instead and would like to change in to variable , so i can proceed for looping function.

Thanks in advance

Here's my current script

ub GSAP_VF01() 'setting the connection with sap: Dim App, Connection, session As Object Set SapGuiAuto = GetObject("SAPGUI") Set App = SapGuiAuto.GetScriptingEngine Set Connection = App.Children(0) Set session = Connection.Children(0)

session.findById("wnd[0]").resizeWorkingPane 138, 23, False session.findById("wnd[0]/tbar[0]/okcd").Text = "vf01" session.findById("wnd[0]").sendVKey 0 session.findById("wnd[0]/usr/cmbRV60A-FKART").Key = "ZF5" session.findById("wnd[0]/usr/ctxtRV60A-FKDAT").Text = Range("D3") session.findById("wnd[0]/usr/tblSAPMV60ATCTRL_ERF_FAKT/ctxtKOMFK-VBELN[0,0]").Text = Range("C3") session.findById("wnd[0]").sendVKey 0 session.findById("wnd[0]/usr/btnTC_OUTPUT").press session.findById("wnd[0]/usr/tblSAPDV70ATC_NAST3/ctxtDNAST-KSCHL[1,1]").Text = "zina" session.findById("wnd[0]/usr/tblSAPDV70ATC_NAST3/ctxtDNAST-KSCHL[1,2]").Text = "zinb" session.findById("wnd[0]/usr/tblSAPDV70ATC_NAST3/ctxtDNAST-KSCHL[1,2]").SetFocus session.findById("wnd[0]/usr/tblSAPDV70ATC_NAST3/ctxtDNAST-KSCHL[1,2]").caretPosition = 4 session.findById("wnd[0]").sendVKey 0 session.findById("wnd[0]/usr/tblSAPDV70ATC_NAST3").getAbsoluteRow(0).Selected = True session.findById("wnd[0]/usr/tblSAPDV70ATC_NAST3").getAbsoluteRow(1).Selected = True session.findById("wnd[0]/usr/tblSAPDV70ATC_NAST3").getAbsoluteRow(2).Selected = True session.findById("wnd[0]/usr/tblSAPDV70ATC_NAST3/lblDV70A-STATUSICON[0,2]").SetFocus session.findById("wnd[0]/usr/tblSAPDV70ATC_NAST3/lblDV70A-STATUSICON[0,2]").caretPosition = 0 session.findById("wnd[0]/tbar[1]/btn[2]").press session.findById("wnd[0]/usr/ctxtNAST-LDEST").Text = "CBJ02P167_SMPS" session.findById("wnd[0]/usr/ctxtNAST-LDEST").caretPosition = 14 session.findById("wnd[0]").sendVKey 0 session.findById("wnd[0]/tbar[0]/btn[3]").press session.findById("wnd[0]/tbar[1]/btn[2]").press session.findById("wnd[0]/usr/ctxtNAST-LDEST").Text = "CBJ02P167_SMPS" session.findById("wnd[0]/usr/ctxtNAST-LDEST").caretPosition = 14 session.findById("wnd[0]").sendVKey 0 session.findById("wnd[0]/tbar[0]/btn[3]").press session.findById("wnd[0]/tbar[1]/btn[2]").press session.findById("wnd[0]/usr/ctxtNAST-LDEST").Text = "CBJ02P167_SMPS" session.findById("wnd[0]/usr/ctxtNAST-LDEST").SetFocus session.findById("wnd[0]/usr/ctxtNAST-LDEST").caretPosition = 14 session.findById("wnd[0]").sendVKey 0 session.findById("wnd[0]/tbar[0]/btn[3]").press session.findById("wnd[0]/tbar[0]/btn[11]").press session.findById("wnd[0]/tbar[0]/okcd").Text = "/nvf03" session.findById("wnd[0]").sendVKey 0 session.findById("wnd[0]/mbar/menu[0]/menu[11]").Select session.findById("wnd[1]/usr/tblSAPLVMSGTABCONTROL").getAbsoluteRow(0).Selected = True session.findById("wnd[1]/tbar[0]/btn[37]").press session.findById("wnd[0]/tbar[0]/okcd").Text = "pdf!" session.findById("wnd[0]").sendVKey 0

End Sub