How to login SAP GUI through excel VBA code? ERROR 438

SavioBR

New Member
Joined
Mar 30, 2022
Messages
2
Office Version
  1. 2016
Platform
  1. Windows
I've been searching on my own and I've failed so far, I already tried changing the line "Set session = Connection.Children()" "to Set session = Connection.Children(0)" or 1 but no progress so far...

My version of the SAP is 6.0

Here's the full code that I've tried so far

VBA Code:
Private Sub SapConn()

Dim Appl As Object
Dim Connection As Object
Dim session As Object
Dim WshShell As Object
Dim SapGui As Object

'file directory
Shell "C:\Program Files (x86)\SAP\FrontEnd\SAPgui\saplogon.exe", 4
Set WshShell = CreateObject("WScript.Shell")

Do Until WshShell.AppActivate("SAP Logon ")
    Application.Wait Now + TimeValue("0:00:01")
Loop

Set WshShell = Nothing

Set SapGui = GetObject("SAPGUI")
Set Appl = SapGui.GetScriptingEngine
Set Connection = Appl.Openconnection("1.1 - Sap ECC Leader Produção.", _
    True)
Set session = Connection.Children()

'username and password

'BELOW I'M GETTINT ERROR NUMBER 438

session.findById("wnd[0]/usr/txtRSYST-MANDT").Text = "400"            '<<<< HERE
session.findById("wnd[0]/usr/txtRSYST-BNAME").Text = "mylogin"        '<<<< HERE
session.findById("wnd[0]/usr/pwdRSYST-BCODE").Text = "mypass"         '<<<< HERE
session.findById("wnd[0]/usr/txtRSYST-LANGU").Text = "PT"             '<<<< HERE

If session.Children.Count > 1 Then

    answer = MsgBox("You've got opened SAP already," & _
"please leave and try again", vbOKOnly, "Opened SAP")

    session.findById("wnd[1]/usr/radMULTI_LOGON_OPT3").Select
    session.findById("wnd[1]/usr/radMULTI_LOGON_OPT3").SetFocus
    session.findById("wnd[1]/tbar[0]/btn[0]").press

    Exit Sub

End If

session.findById("wnd[0]").maximize
session.findById("wnd[0]").sendVKey 0

Any help would be appreciated
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
For anyone in the future who might face this problem as well, I got the solution in my case, I just needed to change one code, which is:

Session = Connection.Children.Item(0)
 
Upvote 0
Solution

Forum statistics

Threads
1,223,234
Messages
6,170,891
Members
452,366
Latest member
TePunaBloke

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top