Hello Hypetia,
Sorry it took me so long to come back and say thank you but I was under the gun. Your code was exactly what I needed. After you got me pointed in the right direction, here is some code I found and modified slightly to return the class name based on the Window title. It came from the AllAPI site at
http://www.mentalis.org/index2.shtml.
Based on your answer above you probably already know this but just in case I thought I would post it.
I also found a similar thread on the VB API forum:
Thread711-663482.
Private Declare Function FindWindow Lib "user32" Alias _
"FindWindowA" (ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long
Private Declare Function GetClassName Lib "user32" Alias _
"GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName _
As String, ByVal nMaxCount As Long) As Long
Private Declare Function ShowWindow Lib "user32" _
(ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Const SW_SHOWNORMAL = 1
Const gcClassnameMSWord = "OpusApp"
Const gcClassnameMSExcel = "XLMAIN"
Const gcClassnameNotePad = "Notepad"
Public Sub GetClassNameFromTitle()
Dim sInput As String, lpClassName As String
Dim nMaxCount As Long, lresult As Long, hwnd As Long
nMaxCount = 256
lpClassName = Space(nMaxCount)
sInput = InputBox("Enter the exact window title:" + _
Chr$(13) + Chr$(10) + "Note: must be an exact match")
hwnd = FindWindow(vbNullString, sInput)
If hwnd = 0 Then
MsgBox "Couldn't find the window."
Else
lresult = GetClassName(hwnd, lpClassName, nMaxCount)
MsgBox "Window: " + sInput + Chr$(13) + Chr$(10) + _
"Classname: " + Left$(lpClassName, lresult)
Debug.Print sInput & ": " & Left$(lpClassName, lresult)
End If
End Sub
Thanks again for your helpfulness!
Have a great day!
j2consulting@yahoo.com