Skip to Content
Former Member
Feb 01, 2017 at 08:36 AM

Create new SAP session with VBA from Excel

879 Views Last edit Feb 01, 2017 at 08:38 AM 3 rev

I have a VBA-script in Excel to download data from SAP. Everything works fine, but when it's launched it always takes an existing SAP-session to run the script (even if another transaction was open in that session). So, I'd like to first open an new SAP-session to run the script there, but haven't found a solution yet.

Here's the beginning of my current script:

Sub ExportSAP()
Set SapGuiAuto = GetObject("SAPGUI")
Set SAPApp = SapGuiAuto.GetScriptingEngine
Set SAPCon = SAPApp.Children(0)
Set session = SAPCon.Children(0)

session.StartTransaction "CADO"
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[1]/usr/txtV-LOW").Text = "BE51_PTW/MD"