Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Bring instance of program forward?

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
I have the code below that opens notepad...where would I put an IF statement to say either...bring the window forward or open a new one? I put comments in there but I"m not sure if that's where they go

Private Sub Command1_Click()
Dim path As String
Dim ret As Long
path = Space$(255)

ret = GetWindowsDirectory(path, 255)
path = Left$(path, ret)
path = path & "\notepad.exe" ' this is just to get the notepad path

' use this call instead of standard Shell function

' IF NOTEPAD IS OPEN - BRING FORWARD
'ELSE
Module1.ShellIt (path)

End Sub

 
If you want a really dirty quick way, you can use the error returned by appactivate when a window does not exist

On Error Resume Next
AppActivate "Notepad"
If Err.Number = 5 Then
Shell "notepad", vbNormalFocus
End If
Err.Clear

If notepad is already open, this sets focus to it, but does not change it's window state (minimized, maximized, etc) David Moore
dm7941@sbc.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top