on 2021 Feb 12 3:34 PM
Hi everybody,
creatin' a macro in excel for my company it would be useful to connect to our SAP 750, retrieving data from it.
As a "sufficient macro developer" (it's not my first task) I've copied a lot of codes to try to understand how to connect VBA code to SAP but I'm still not understanding where I'm doing wrong.
If Not IsObject(SAPguiApp) Then
Set SAPguiApp = CreateObject("Sapgui.ScriptingCtrl.1")
End If
If Not IsObject(Connection) Then
Set Connection = SAPguiApp.OpenConnection("SYSTEMNAME", True)
End If
If Not IsObject(session) Then
Set session = Connection.Children(0)
End If
session.findById("wnd[0]").maximize
In every forum I've searched this seems the code that work the most but I'm still receiving error during connectin to the children. Pratically I can correctly open the SAP Logon window and open the session named "SYSTEMNAME" (that in my case is SSO) but I cant do anything else (like interact with GUI) 'cause the code stop to work in the line "Set session = Connection.Children(0)".
The errors retriving is "The enumerator of the collection cannot find en element with the specified index", deleting reference number (becoming "()" insteead of "(0)" ) the code continue to work (but I dont understand why) and stops in the next line when it trying to interact with SAP window ("session" variable is empty).
I've the scripts actived on SAP but the only way to record it is using the Synactive GuiXT because the related option in menu is greyed, so I can't even examine the code to try to understand where I'm wrong. As a simple user (the last hired in this office) I have basic access to SAP transactions and not to much experience with the transactions functions.
Is there maybe any API/DLL to load in excel prior to run that code? In many forum this code work but I dont understand why not in my PC.
Can anyone help?
Many many many thanks in advance
Request clarification before answering.
mmarco
Hello Marco,
welcome in the SAP Community. Your code looks good and it works. I can simulate your error.

To solve this problem open transaction code RZ11 (Maintain Profile Parameters) and enter the parameter name sapgui/user_scripting.

I assume your current value is false.

Set the current value to true. Press Change Value button in the toolbar.

Set the new value to true, activate switch on all servers and save it.

Now your code should work as expected.
You can find more information about SAP GUI Scripting Profile Parameters in the SAP GUI Scripting Security Guide.
Let us know your results.
Best regards
Stefan
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi st.schnell and thanks for the reply,
unfortunately I dont have permission to open that transaction and nor all my offices colleagues (who normally have a more high level of permission in SAP), actually I don't have an admin permission even for my PC.
Should I presume the scripting is disabled server-side? If it is the only way to avoid my error I suppose I'm screwed 😄
mmarco
Hello Marco,
the disabled server-side scripting explains the program behavior. Talk with your admin. If he has any concerns, the SAP GUI Scripting can also be released for specific users with appropriate permissions. Take a look at the profile parameter sapgui/user_scripting_per_user.
Best regards
Stefan
| User | Count |
|---|---|
| 18 | |
| 7 | |
| 7 | |
| 6 | |
| 4 | |
| 4 | |
| 4 | |
| 2 | |
| 2 | |
| 2 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.