' Display the title bar text of the foreground window. Dim hforewnd As Long ' receives handle of foreground window Dim slength As Long ' length of foreground window's title bar text Dim wintext As String ' buffer for foreground window's title bar text Dim retval As Long ' return value hforewnd = GetForegroundWindow() ' determine the foreground window slength = GetWindowTextLength(hforewnd) + 1 ' length of its title bar text wintext = Space(slength) ' make room in the buffer to receive the text retval = GetWindowText(hforewnd, wintext, slength) ' get title bar text wintext = Left(wintext, slength - 1) ' remove null character from end of string Debug.Print "The window "; wintext; " is the foreground window."