i try to write a macro which transports changes in an excel sheet directly to SAP.
My macro already starts as soon as there is a change in the excel sheet. The problem is: sometimes it works fine with the SAP sometimes i get this "Run-time error 91 : Object variable or with block variable not set
My macro starts like this:
Public Einheit As Variant
Public TechnischerPlatz As Variant
Set SAPsession = Nothing
Set SAPConnection = Nothing
Set SAPGuiAuto = Nothing
If Not IsObject(SAPapplication) Then
Set SAPGuiAuto = GetObject("SAPGUI")
Set SAPapplication = SAPGuiAuto.GetScriptingEngine
If Not IsObject(SAPConnection) Then
Set SAPConnection = SAPapplication.Children(0)
If Not IsObject(SAPsession) Then
Set SAPsession = SAPConnection.Children(0)
If IsObject(WScript) Then
WScript.ConnectObject SAPsession, "on"
WScript.ConnectObject Application, "on"
I use different Subs because i don´t want to allow the SAP Access every single time there is a change in the Excel-Sheet. I the end it should run kind of automated. So that someone start the SAP every morning and for the rest of the day the excel sheet and SAP run on there own.
It´s the second time i use macros and SAP Scripting so i hope there is some "easy mistake" i can´t find because of my bad macro skills.
Can anybody help me?