Activate an App by a Partial Window Title Visual basic
'PUT ALL THIS CODE (DECLARATIONS AND FUNCTIONS)
'INTO A .BAS MODULE.
Option Explicit
Option Compare Text
Private Declare Function EnumWindows Lib "user32" _
(ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
Private Declare Function GetWindowText Lib "user32" Alias _
"GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, _
ByVal cch As Long) As Long
Private psAppNameContains As String
Private pbFound as Boolean
'Code for form:
Public Function AppActivateByStringPart(StringPart As String) As Boolean
'PURPOSE: Activates the first window that contains any part of
'of StringPart
'PARAMETERS:
'AppNamePart = Any Part of the WindowTitle for the App
'RETURNS: True if successful (i.e., a running app was found)
'false otherwise (e.g., no running app was found with StringPart
'as part of a title, or an error occurred
'EXAMPLE:
' ActivateAppByStringPart "Microsoft Internet Explorer"
'Will Activate the first running instance of IE it finds,
'even though the window title in most cases does
'not begin with with "Microsoft Internet Explorer"
Dim lRet As Long
psAppNameContains = StringPart
lRet = EnumWindows(AddressOf CheckForInstance, 0)
AppActivateByStringPart = pbFound
'reset
pbFound = False
End Function
Private Function CheckForInstance(ByVal lhWnd As Long, ByVal _
lParam As Long) As Long
Dim sTitle As String
Dim lRet As Long
Dim iNew As Integer
If Trim(psAppNameContains = "") Then
CheckForInstance = False
Exit Function
End If
sTitle = Space(255)
lRet = GetWindowText(lhWnd, sTitle, 255)
sTitle = StripNull(sTitle)
If InStr(sTitle, psAppNameContains) > 0 Then
'we're done, stop looking
CheckForInstance = False
pbFound = True
AppActivate sTitle
Else
CheckForInstance = True
End If
End Function
Private Function StripNull(ByVal InString As String) As String
'Input: String containing null terminator (Chr(0))
'Returns: all character before the null terminator
Dim iNull As Integer
If Len(InString) > 0 Then
iNull = InStr(InString, vbNullChar)
Select Case iNull
Case 0
StripNull = InString
Case 1
StripNull = ""
Case Else
StripNull = Left$(InString, iNull - 1)
End Select
End If
End Function
Or you can try - me.show vbModal
this will force the window to be shown