Hello Adam,
it is possible with the ID property of the GuiFocus property of the GuiMainWindow object:
ActID = Ses.ActiveWindow.GuiFocus.ID
Here a VBA example:
'-Begin-----------------------------------------------------------------
Sub Test()
'-Variables---------------------------------------------------------
Dim SAPGUI As Object
Dim App As SAPFEWSELib.GuiApplication
Dim Con As SAPFEWSELib.GuiConnection
Dim Ses As SAPFEWSELib.GuiSession
Dim ActID As String
Set SAPGUI = GetObject("SAPGUI")
If Not IsObject(SAPGUI) Then
Exit Sub
End If
Set App = SAPGUI.GetScriptingEngine()
If Not IsObject(App) Then
SAPGUI = Nothing
Exit Sub
End If
Set Con = App.Children(0)
If Not IsObject(Con) Then
Set App = Nothing
Set SAPGUI = Nothing
Exit Sub
End If
Set Ses = Con.Sessions(0)
If Not IsObject(Ses) Then
Set Con = Nothing
Set App = Nothing
Set SAPGUI = Nothing
Exit Sub
End If
Dim App As SAPFEWSELib.GuiApplication
Dim Con As SAPFEWSELib.GuiConnection
Dim Ses As SAPFEWSELib.GuiSession
Dim ActID As String
Set SAPGUI = GetObject("SAPGUI")
If Not IsObject(SAPGUI) Then
Exit Sub
End If
Set App = SAPGUI.GetScriptingEngine()
If Not IsObject(App) Then
SAPGUI = Nothing
Exit Sub
End If
Set Con = App.Children(0)
If Not IsObject(Con) Then
Set App = Nothing
Set SAPGUI = Nothing
Exit Sub
End If
Set Ses = Con.Sessions(0)
If Not IsObject(Ses) Then
Set Con = Nothing
Set App = Nothing
Set SAPGUI = Nothing
Exit Sub
End If
ActID = Ses.ActiveWindow.GuiFocus.ID
Debug.Print ActID
Set Ses = Nothing
Set Con = Nothing
Set App = Nothing
Set SAPGUI = Nothing
End Sub
'-End-------------------------------------------------------------------
And a VBScript example:
'-Begin-----------------------------------------------------------------
If Not IsObject(application) Then
Set SapGuiAuto = GetObject("SAPGUI")
Set application = SapGuiAuto.GetScriptingEngine
End If
If Not IsObject(connection) Then
Set connection = application.Children(0)
End If
If Not IsObject(session) Then
Set session = connection.Children(0)
End If
ActID = session.ActiveWindow.GuiFocus.ID
MsgBox ActID
'-End-------------------------------------------------------------------
Hope it helps, let us know.
Cheers
Stefan