on 06-07-2017 9:35 PM
Hello Community,
I want to read out data from SAP through Excel with scripting. I found the following Code but it is not running. It don´t jump into the first If statement, why not?
If I comment out the first If statement I get:
Run-time error '-2147221020 ( 800401e4)' Automation error Invalid syntax
Many thanks in advance.
Public SAPguiAPP As GuiApplication
Public oConnection As GuiConnection
Public oSession As GuiSession
Public Sub Test()
If Not IsObject(SAPguiAPP) Then
Set SapGuiAuto = GetObject("SAPGUI")
Set SAPguiAPP = SapGuiAuto.GetScriptingEngine
End If
If Not IsObject(Connection) Then
Set oConnection = SAPguiAPP.Children(0)
End If
If Not IsObject(Session) Then
Set oSession = oConnection.Children(0)
End If
If IsObject(WScript) Then
WScript.ConnectObject oSession, "on"
WScript.ConnectObject SAPguiAPP, "on"
End If
oSession.FindById("wnd[0]").Maximize
oSession.FindById("wnd[0]").resizeWorkingPane 109, 26, False
oSession.FindById("wnd[0]/tbar[0]/okcd").Text = "ca03"
Set Session = Nothing
Set Connection = Nothing
Set SAPguiAPP = Nothing
End Sub
Hello Lars,
try the following code.
Public SAPguiAPP As GuiApplication
Public oConnection As GuiConnection
Public oSession As GuiSession
Public Sub Test()
If SAPguiAPP Is Nothing Then
Set SapGuiAuto = GetObject("SAPGUI")
Set SAPguiAPP = SapGuiAuto.GetScriptingEngine
End If
If oConnection Is Nothing Then
Set oConnection = SAPguiAPP.Children(0)
End If
If oSession Is Nothing Then
Set oSession = oConnection.Children(0)
End If
oSession.FindById("wnd[0]").Maximize
oSession.FindById("wnd[0]").resizeWorkingPane 109, 26, False
oSession.FindById("wnd[0]/tbar[0]/okcd").Text = "ca03"
Set oSession = Nothing
Set oConnection = Nothing
Set SAPguiAPP = Nothing
End Sub
Let us know your result.
Cheers
Stefan
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks Stefan, it is working.
But an "o" in the following part right?
Set oSession = Nothing
Set oConnection = Nothing
Set SAPguiAPP = Nothing
Greetings
Lars
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Great, Will actions (business processes like CRM business partner creation etc.,) be automatable via this way in VBA?
We have test data preparation automated via VBA. this one is interesting.! Share more inputs pls.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
83 | |
10 | |
10 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.