What I gave you previously works for a separate app (like Word or Excel).
This works for killing the second instance of the same app and activating/maximizing the first instance:Code:Option Explicit Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long Private Const SW_SHOWMAXIMIZED = 3 Private Sub Form_Load() Dim lhwnd As Long Dim lRtrn As Long Dim sFrmCaptn As String Dim X As Form 'Get Caption to Search For sFrmCaptn = Me.Caption Me.Caption = "" 'Search for Window / Get its Handle lhwnd = FindWindow(vbNullString, sFrmCaptn) 'If Another Window Found If lhwnd <> 0 Then 'Activate and Maximize Window lRtrn = ShowWindow(lhwnd, SW_SHOWMAXIMIZED) 'Kill App For Each X In Forms Unload X Set X = Nothing Next Unload Me 'If No Other Window Found Else 'Set Caption back to Original Caption Me.Caption = sFrmCaptn End If End Sub




Reply With Quote