Home |
Search |
Today's Posts |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi again,
I am using Peter Beache's code as follows to test if there is another instance running but I don't know how to close it if it is You can send a WM_CLOSE message to the hWnd in question. See modified code below. Regards, Vic Eldridge Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _ (ByVal lpClassName As String, _ lpWindowName As Any) As Long Private Declare Function GetNextWindow Lib "user32" Alias "GetWindow" _ (ByVal hwnd As Long, _ ByVal wFlag As Long) 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 PostMessage Lib "user32" Alias "PostMessageA" _ (ByVal hwnd As Long, _ ByVal wMsg As Long, _ ByVal wParam As Long, _ ByVal lParam As Long) As Long Private Const GW_HWNDNEXT = 2 Private Const WM_CLOSE = &H10 Sub DupeXLRunning() Dim lRet& Dim StrRet$ Dim nLen& lRet& = FindWindow("XLMain", ByVal 0&) ' Now this will always return a valid HWND, ' being the handle of this instance of XL Do lRet& = GetNextWindow(lRet&, GW_HWNDNEXT) If lRet& = 0 Then Exit Do StrRet$ = Space$(100) nLen& = GetClassName(lRet&, StrRet$, 100) StrRet$ = Left$(StrRet$, nLen&) If UCase$(StrRet$) = "XLMAIN" Then MsgBox "Duplicate version of XL found." PostMessage lRet&, WM_CLOSE, 0&, 0& Exit Sub End If Loop MsgBox "Only one version of XL running" End Sub |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Excel - New Instance | Excel Discussion (Misc queries) | |||
why do all excel worksheets/workbooks close when I close one? | Excel Discussion (Misc queries) | |||
Excel shoud not close all active books when clicking close button | Excel Discussion (Misc queries) | |||
excel - Windows close button (x) should only close active workboo. | Setting up and Configuration of Excel | |||
Second instance of Excel | Excel Programming |