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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SendKeys - How to Check to Make Sure the Correct Application is Active 1

Status
Not open for further replies.

kjv1611

New member
Jul 9, 2003
10,758
US
I have a SendKeys instance working currently - of course, it aint the purtiest way of doing things. [wink]

For what I am wanting to do, it seemed that SendKeys is the only way I could get it accomplished. So, it's working.

However, I would like to somehow (if possible using VBA) check to make sure the correct application is the active window, and that it is open in the first place. If it is not open, I would like to open and activate it, but only activate it and use the sendkeys command if it is already open. I tried searching around, but could not seem to find anything that explains how to check on an application being open.

The particular application to which I am sending the keystrokes is a web application on our company Intranet. And at least for now, I'm just doing this for my own good, as it wouldn't be something I could get approved by all levels for the entire company - I've recommended it before.

Without further ado, here is my current code using SendKeys:
Code:
Private Sub cmdPaste_Click()
    Dim x As Integer
    x = 1
    
    AppActivate "IntranetProgram"
    SendKeys "%V"
    SendKeys "R", 300
    AppActivate "IntranetProgram"
    SendKeys "{TAB 12}"
    
    For x = 1 To 5
        SendKeys "{TAB}", 10
        SendKeys "158560941", 10
    Next x

    SendKeys "%s"

End Sub

I tried digging around for options with ActiveWindow and Shell, but couldn't find anything. Everything I could find for ActiveWindow seemed to only work with Excel (unless perhaps, I'm missing the correct reference to use that option). And for Shell, I couldn't find anything to say "is the application running?"

Also, in case it helps any, this specific Intranet application can only be opened in Internet Explorer. Our current version of Internet Explorer is 6.0.2900.2180.xpsp_sp2_gdr.....

Thanks for any suggestions, code snippets, references, explanations, etc.

--

"If to err is human, then I must be some kind of human!" -Me
 
How is your intranet application launched ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
It is launched basically by a local intranet address.

So it is something like:


And that's the whole link. We have certain web-based applications setup like that, so we can go from our intranet page, or we can just type in the address if we know it.



--

"If to err is human, then I must be some kind of human!" -Me
 
Or, I suppose to be possibly a little more accurate, when the application is open, it shows " in the address bar of Internet Explorer 6.

We generally access it from an Intranet link or just typing in "Application" in the address bar.

--

"If to err is human, then I must be some kind of human!" -Me
 
Hmmm, perhaps it isn't possible? Or am I a loony toon?
[wink]

--

"If to err is human, then I must be some kind of human!" -Me
 
I'm sure it's possible to find the active Window with an API, just don't ask me which one.

I would consider using the Internet Browser control and opening the Intranet app through that, you will have much more control. You would be able to access the DOM of whatever is loaded in the browser control, and therefore wouldn't have to rely on SendKeys.

I can't give much more info than that, it's been years since I've done something like that.

 
Hmmm, I'll see what I can find. That sounds VERY interesting indeed! Thanks for the tip!

--

"If to err is human, then I must be some kind of human!" -Me
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top