0

I need to get the user ID into VBA code.

Like on the picture:

enter image description here

I tried

UserId = Session.FindById("wnd[0]").User

But it failed. What's the right way?

Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
Sergey Belousov
  • 153
  • 2
  • 12
  • 1
    I think we need a bit more information to be able to help with this – Tom Apr 17 '19 at 09:43
  • Is this the Excel that’s embedded in an ALV list or some other connected SAP source? You’re showing SAPGui but but how is that interacting with Excel? – Skin Apr 17 '19 at 09:44

2 Answers2

1

Even easier would be:

UserId = Session.Info.User
0

This proved to be easy:

Sub Getuser()



Dim SapGuiAuto
Dim SetApp
Dim Connection
Dim Session



Set SapGuiAuto = GetObject("SAPGUI")
Set SetApp = SapGuiAuto.GetScriptingEngine
Set Connection = SetApp.Children(0)
Set Session = Connection.Children(0)

Session.FindById("wnd[0]").Maximize
Session.FindById("wnd[0]/mbar/menu[4]/menu[11]").Select

MsgBox Session.FindById("wnd[1]/usr/txtSYST-UNAME").Text
Session.FindById("wnd[1]/tbar[0]/btn[0]").Press

End Sub
Sergey Belousov
  • 153
  • 2
  • 12