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!

How do I bring a window to the front??? Please help!!!

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
If I have an instance of notepad open...what command do I use to bring it to the front (bring it forward so user can use it, set the focus to be on notepad) thanks Please help, I need to get this issue resolved quick..
 
the AppActivate command should do the trick.

try this

AppActivate "Notepad"


David Moore
dm7941@sbc.com
 
is there a way I can do an if statement. I have code that opens notepad, but is there a way to say

If notepad is open
AppActivate "notepad"
else
Open Notepad...


Thanks
 
I just wrote a dirty bit of code for another question on the same thing :)

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

It uses the error returned by the appactivate to tell if an instance is already open. Hope this helps! David Moore
dm7941@sbc.com
 
Sorry i'm new to this..where would I place that code? In my form_load section where I have notepad opening?
 
put it whereever you want to activate the notepad
David Moore
dm7941@sbc.com
 
The code worked great, but now there is one more thing I am wondering is possible. What I want to be able to do is, from the command line if I run the .exe file is there a way I can specify which program I want to open. i.e. instead of calculator the user can open notepad etc...kinda like the following

* THIS IS THE COMMAND LINE i.e
Open: Prog1.exe notepad.exe
Open: Prog1.exe calc.exe

* user wants Prog1.exe to open notepad or calculator
Do I just replace the name of the program with %1 as for example below? If anyone knows the solution please let me know...thanks :)


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

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top