Mike Eghtebas
asked on
How to find class of excel running...vb6
I have:
Declare Function GetDesktopWindow Lib"user32" () As Long
Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" _
(ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
'------------------------- ---------- ---------- ---------- ---------- ---------
Function IsWorkBookOpen(strWBName As String) As Boolean
Dim dWnd As Long, hWnd As Long, mWnd As Long, cWnd As Long
dWnd = GetDesktopWindow
hWnd = FindWindowEx(dWnd, 0&,"XLMAIN", vbNullString)
mWnd = FindWindowEx(hWnd, 0&,"XLDESK", vbNullString)
While mWnd <> 0 And cWnd = 0
cWnd = FindWindowEx(mWnd, 0&,"EXCEL7", strWBName) '<--- using "EXCEL7" for class
hWnd = FindWindowEx(dWnd, hWnd,"XLMAIN", vbNullString)
mWnd = FindWindowEx(hWnd, 0&,"XLDESK", vbNullString)
Wend
If cWnd > 0 Then
IsWorkBookOpen = True
End If
End Function
'------------------------- -
I want to replace above line with:
Dim strExcelClass As String
strExcelClass = <need help here to determine excel class>
cWnd = FindWindowEx(mWnd, 0&,strExcelClass , strWBName) '<--- and use strExcelClass in place of "EXCEL7"
Do you know what is the syntax for it.
Thanks.
Declare Function GetDesktopWindow Lib"user32" () As Long
Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" _
(ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
'-------------------------
Function IsWorkBookOpen(strWBName As String) As Boolean
Dim dWnd As Long, hWnd As Long, mWnd As Long, cWnd As Long
dWnd = GetDesktopWindow
hWnd = FindWindowEx(dWnd, 0&,"XLMAIN", vbNullString)
mWnd = FindWindowEx(hWnd, 0&,"XLDESK", vbNullString)
While mWnd <> 0 And cWnd = 0
cWnd = FindWindowEx(mWnd, 0&,"EXCEL7", strWBName) '<--- using "EXCEL7" for class
hWnd = FindWindowEx(dWnd, hWnd,"XLMAIN", vbNullString)
mWnd = FindWindowEx(hWnd, 0&,"XLDESK", vbNullString)
Wend
If cWnd > 0 Then
IsWorkBookOpen = True
End If
End Function
'-------------------------
I want to replace above line with:
Dim strExcelClass As String
strExcelClass = <need help here to determine excel class>
cWnd = FindWindowEx(mWnd, 0&,strExcelClass , strWBName) '<--- and use strExcelClass in place of "EXCEL7"
Do you know what is the syntax for it.
Thanks.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Function IsWorkBookOpen(strWBName As String) As Boolean
Dim oXL As Object
Dim oXlWb As Object
IsWorkBookOpen = False
On Error Resume Next
'Get open excel application
Set oXL = GetObject(, "excel.application")
'Search each workbook name
For Each oXlWb In oXL.Workbooks
Debug.Print oXlWb.Name
If (UCase(oXlWb.Name) = UCase(strWBName)) Then
IsWorkBookOpen = True
Exit For
End If
Next
Set oXlWb = Nothing
Set oXL = Nothing
End Function
Hope it helps.