use GetForeGroundWindow Api to retrieve handle of active window. and use getWindowText for caption.
See this example code
Public Declare Function GetForegroundWindow Lib "user32" () As Long
Public Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Public Function getWindCaption() As String
Dim strCaption As String
'Create a buffer
strCaption = String(250, Chr$(0))
'Get the windowtext
Dim cW As Long
cW = GetForegroundWindow
If cW > 0 Then
GetWindowText cW, strCaption, 250
strCaption = Left$(strCaption, InStr(strCaption, Chr$(0)) - 1)
getWindCaption = strCaption
End If
End Function