Skip to Content
0
Former Member
Jan 02, 2013 at 03:05 PM

SAP connected with Excel

127 Views

Hello everyone,

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
Public SAPGuiAuto
Public SAPConnetion
Public SAPsession
Public j


Sub SAP_trennen()

Set SAPsession = Nothing
Set SAPConnection = Nothing
Set SAPGuiAuto = Nothing

End Sub

Sub SAP_anbinden()

If Not IsObject(SAPapplication) Then
Set SAPGuiAuto = GetObject("SAPGUI")
Set SAPapplication = SAPGuiAuto.GetScriptingEngine
End If
If Not IsObject(SAPConnection) Then
Set SAPConnection = SAPapplication.Children(0)
End If
If Not IsObject(SAPsession) Then
Set SAPsession = SAPConnection.Children(0)
End If
If IsObject(WScript) Then
WScript.ConnectObject SAPsession, "on"
WScript.ConnectObject Application, "on"
End If

End Sub

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?

Best regards

Eva