Re: Another AppActivate Question

G

Guxu

I have having the exact same problem. The AppActivate works fine some
applications such as notepad.exe, calc.exe, but it will not work for
Explorer.exe and etc. I kept getting Error 5 as well.

dblTaskID = Shell("explorer.exe", 1)
AppActivate dblTaskID

Can some explain why?
 
B

Bruce M. Thompson

I have having the exact same problem. The AppActivate works fine some
applications such as notepad.exe, calc.exe, but it will not work for
Explorer.exe and etc. I kept getting Error 5 as well.

dblTaskID = Shell("explorer.exe", 1)
AppActivate dblTaskID

Can some explain why?

Well, this may be a case where the resulting process does not own a window, so
this process can't be found in the list of processes that AppActivate searches
(this only happens when you pass the task ID as an argument). I missed this one
when Matt asked the same question and I'm not sure why, but this would appear to
be the explanation. You can pass the string in the title bar of the resulting
explorer session to the AppActivate statement instead of the task ID and it will
work because it will then only search the open windows for a matching title bar
string.
 
V

Van T. Dinh

I tested in WXP andAXP and got the same error message but the AppActivate
definitely worked. Note that the normal (preferred?) first argument is the
String argument "Title", not a variant (double) even though the Shell value
is is acceptable. All I can think of is that is is a spurious error message
(perhaps while checking for the Title String.

You can simply trap the Error 5 and ignore it. Here is the lazy code I used
to test:

***Tested in WXP + AXP***
Public Sub TestOpenExplorer()
Dim varTask as Variant

varTask = Shell("Explorer.exe ""C:\Program Files""", vbNormalNoFocus)
DoEvents
On Error Resume Next
AppActivate varTask
End Sub
***Code ends***

HTH
Van T. Dinh
MVP (Access)
 
B

Bruce M. Thompson

Hi Van. I tested under WinXP and A2K and found that AppActivate did not work
with explorer.exe when passed the TaskID (tested by setting the focus to another
application before issuing the AppActivate statement). It did work, however, and
without any error message, if I passed the app's Title string to the AppActivate
statement.

Do you know if Explorer *owns* a window?
 
V

Van T. Dinh

Hi Bruce

I am fairly sure it does because you can use the Title Text to find the
window handle using the API fn GetWindows.

The thing I am not too sure is how to use the TaskID (returned by Shell) to
find the handle or the Title Text.

Sorry, I don't have the WXP / A2K combination to test it out.

--
HTH
Van T. Dinh
MVP (Access)
 
R

Ricky

I having the same error with DOS programs ?????

Bruce M. Thompson said:
Well, this may be a case where the resulting process does not own a window, so
this process can't be found in the list of processes that AppActivate searches
(this only happens when you pass the task ID as an argument). I missed this one
when Matt asked the same question and I'm not sure why, but this would appear to
be the explanation. You can pass the string in the title bar of the resulting
explorer session to the AppActivate statement instead of the task ID and it will
work because it will then only search the open windows for a matching title bar
string.
 
B

Bruce M. Thompson

I having the same error with DOS programs ?????

This is a perfect example of when the process does not own a window
(applications that run in a DOS session and Console applications fall into this
class).
 
B

Bruce M. Thompson

(applications that run in a DOS session and Console applications ...

I know, I know ... same difference. <g>

:)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top