Quantcast
Viewing all articles
Browse latest Browse all 2823

SAP Scripting into Excel using VBA

Hi SCN,

 

 

I am Michael and very much looking forward to discussing my SAP challenges and sharing ideas with the community. Learning is advantageous for everyone. My motto is 'knowledge is power' :-) - I know a lot of you have far more knowledge in this area so very willing to share and learn as much as I can.

 

 

First of all apologies if some of my queries have been answered elsewhere. I have looked and some are similar but just not quite what I am after.

 

Like I say above I would share my ideas too. So to start with I will share a couple of 'beginner' scripts below: -

 

 

Viewing Invoice PDF

 

First of all I wanted an easy to view Excel loader that you pop in the Invoice number and it would go into SAP and open up the PDF version.

This was one of my easiest SAP scripting.

Image may be NSFW.
Clik here to view.
Open Invoice.JPG

Sub Invoice ()

If Not IsObject (anApplication) Then

     Set SapGuiAuto - GetObject (SAPGUI")

     Set anApplication = SapGuiAuto.GetScriptingEngine

End If

If Not IsObject (Connection) Then

     Set Connection = anApplication.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]").resizeWorkingPane 169, 33, False

session.findById("wnd[0]/tbar[0]/okcd").Text = "fb03"

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

session.findById("wnd[0]/usr/txtRF05L-BELNR").Text = Sheets("Sheet1").Cells(4, 2).Value

session.findById("wnd[0]/usr/ctxtRF05L-BUKRS").Text = "<insert company code>"

session.findById("wnd[0]/usr/txtRF05L-GJAHR").Text = Sheets("Sheet1").Cells(4, 3).Value

session.findById("wnd[0]/usr/txtRF05L-GJAHR").SetFocus

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

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

session.findById("wnd[0]/titl/shellcont/shell").pressButton "%GOS_TOOLBOX"

session.findById("wnd[0]/shellcont/shell").pressButton "VIEW_ATTA"

session.findById("wnd[1]/usr/cntlCONTAINER_0100/shellcont/shell").currentCellColumn = "BITM_DESCR"

session.findById("wnd[1]/usr/cntlCONTAINER_0100/shellcont/shell").selectedRows = "0"

session.findById("wnd[1]/usr/cntlCONTAINER_0100/shellcont/shell").doubleClickCurrentCell

 

End Sub

 

Simple and effective! Image may be NSFW.
Clik here to view.

 

I am currently looking at a few small things that I could with assistance please: -

 

We have variances in FI-CO ledger balances showing using KE5T, it would be nice to create a spreadsheet that I could firstly obtain the balances next to my GL codes already listed in Excel and then obtain the GL downloads from both KE5Z and FBL3N so we can pivot the data easily.

 

My script here gets the balances but I would like to auto populate into my existing Excel workbook (KE5T Balance Feb'16.xlsx): -

 

If Not IsObject(anApplication) Then

   Set SapGuiAuto = GetObject("SAPGUI")

   Set anApplication = SapGuiAuto.GetScriptingEngine

End If

If Not IsObject(Connection) Then

   Set Connection = anApplication.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 = "ke5t"

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

session.findById("wnd[0]/usr/chkP_DIFF").Selected = True

session.findById("wnd[0]/usr/ctxtP_BUKRS-LOW").Text = "<comp code>"

session.findById("wnd[0]/usr/txtP_BFRPER").Text = "02"

session.findById("wnd[0]/usr/txtP_BTOPER").Text = "02"

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

session.findById("wnd[0]/usr/ctxtP_RACCT-HIGH").Text = "79999999"

session.findById("wnd[0]/usr/chkP_DIFF").SetFocus

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

 

Thanks

 

Michael


Viewing all articles
Browse latest Browse all 2823

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>