View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 27,285
Default Check if form is open

I had the D and the X backwards - X is for xl2000 and later and D is for
xl97. From a post by Chip Pearson:

William,


You can use the FindWindow API to get the hWnd of the form. The class name
is
"ThunderXFrame" in VBA6 (Excel 2000 and 2002) or "ThunderDFrame" in VBA5
(Excel97). E.g.,


Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
(ByVal hWND As Long, ByVal wMsg As Long, ByVal wParam _

As Long, lParam AsAny) As Long
Public Const WM_CLOSE = &H10


Sub AAA()
Dim hWND As Long
UserForm1.Show vbModeless
#If VBA6 Then
hWND = FindWindow("ThunderDFrame", UserForm1.Caption)
#Else
hWND = FindWindow("ThunderXFrame", UserForm1.Caption)
#End If


SendMessage hWND, WM_CLOSE, 0, 0
End Sub


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


--

Regards,

Tom Ogilvy



"Tom Ogilvy" wrote in message
...
Use the FindWindow API

Using the FindWindow API call to get the Windows handle for an Excel
UserForm:


Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long


Then in your code do:


hWnd = FindWindow ("ThunderDFrame", Me.Caption)
If hWnd = 0 then

msgbox "Not found"

End if



Replace Me.Caption with the caption of the Userform you are searching for.

I believe in Excel 97, the class name is ThunderXFrame



--

Regards,

Tom Ogilvy









"Kev" wrote in message
...
Can someone help me out with this one?
I am trying to determine if an Excel form is open or not from within

Excel.
Thanks in advance.