+ Reply to Thread
Results 1 to 9 of 9

How to put focus to IE

  1. #1
    Registered User
    Join Date
    11-01-2012
    Location
    helsinki, finland
    MS-Off Ver
    Excel 2007
    Posts
    81

    How to put focus to IE

    Hi !

    I'm new to this forum and have a problem that I haven't been able to solve by searching around the internet.
    I need to put the focus to MS Internet Explorer but have not yet find the solution.
    It is quite easy to put focus to Excel like this:

    Please Login or Register  to view this content.
    So what could you put instead of XLMAIN to bring the focus on IE,
    Where could one find a list of short names where also XLMAIN is a member?

    Have not been able to find anything that would function correctly and referring to IE,
    for example "'IEFrame" does not work and that is also the only thing I have found so far.

    In my case IE is open and there is not a need to open it, just to put the focus there.

    Thank you in advance
    keymuu
    Last edited by keymuu; 11-11-2012 at 09:46 AM. Reason: code tags

  2. #2
    Valued Forum Contributor
    Join Date
    02-12-2011
    Location
    The Netherlands
    MS-Off Ver
    365
    Posts
    860

    Re: How to put focus to IE

    Maybe,
    Please Login or Register  to view this content.
    Harry.

  3. #3
    Registered User
    Join Date
    11-01-2012
    Location
    helsinki, finland
    MS-Off Ver
    Excel 2007
    Posts
    81

    Re: How to put focus to IE

    Thank you Harry,

    AppActivate ("Microsoft excel") this does not do anything, runs smoothly over this
    however
    AppActivate ("Windows Internet explorer") this triggers run-time error 5, invalid procedure call or argument

    Can't understand why such a trivial thing can be so difficult to accomplish, or maybe
    one could say "welcome to the Microsoft world" ???

    With kind regards
    keymuu

  4. #4
    Valued Forum Contributor
    Join Date
    02-12-2011
    Location
    The Netherlands
    MS-Off Ver
    365
    Posts
    860

    Re: How to put focus to IE

    Hello Keymuu,

    It works fine to me in Windows XP with Excel 2007.
    Are there differend program names??
    The name in the code is the same as the name on top of the program.
    Last edited by HSV; 11-04-2012 at 07:12 AM.

  5. #5
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: How to put focus to IE

    I've used AutoIT to help me identify names before. Try something like this:

    Please Login or Register  to view this content.
    Please consider:

    Thanking those who helped you. Click the star icon in the lower left part of the contributor's post and add Reputation.
    Cleaning up when you're done. Mark your thread [SOLVED] if you received your answer.

  6. #6
    Registered User
    Join Date
    11-01-2012
    Location
    helsinki, finland
    MS-Off Ver
    Excel 2007
    Posts
    81

    Re: How to put focus to IE

    Hi again!

    thank you abousetta but that code does not put focus on IE,
    maybe it does work in your pc, but not in my (Lenovo T61).
    It runs without errors but do not change focus to IE,
    the focus does not change in any way

    I'm using Windows XP and Office 2007 if that does matter at all.

    regards
    keymuu

  7. #7
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: How to put focus to IE

    This seems to be working for me:

    Please Login or Register  to view this content.
    Maybe you want ShowWindow instead. I have commented that line out.

    abousetta

  8. #8
    Registered User
    Join Date
    11-01-2012
    Location
    helsinki, finland
    MS-Off Ver
    Excel 2007
    Posts
    81

    Re: How to put focus to IE

    Thank you abousetta,

    thank you indeed, you are a real VBA wizard....

    Here are a few comments about this all (set focus to IE):

    lIEHwnd = FindWindow("IEFrame", Application.Caption) returns FALSE (0) and does not work, of course

    then
    lIEHwnd = FindWindow("IEFrame", vbNullString) returns TRUE (133500) and hence works - that is great

    however
    IEShowWindow = ShowWindow(lIEHwnd, 1) returns TRUE (16) but does not change the focus here or there.
    So from this point of view
    it does not work, and it would be nice to know why, or is it again "welcome to the windows world"
    = a lot is going on and one doesn't have a clue what is happening, one thing working in one
    place but not in the other, depending on the settings (in general?) ??

    At last I can continue with what I was working with. Needed to know exactly where the focus between Excel
    and IE is, so I can be sure where it is when writing or reading from one of them. It turned out that Windows
    could suddenly change focus away from IE and that was the reason for looking around for this "set focus".

    With kind regards
    keymuu

  9. #9
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: How to put focus to IE

    From my understanding of how Windows works then ShowWindow(lIEHwnd, 1) should both activate and show the window. ShowWindow(lIEHwnd, 5) should activate only without showing it (if it is hidden beneath other windows or is minimized).

    In all cases, I think these issues are probably better answered in a Windows forum where you will probably find more knowledgeable people able to answer questions related to the Windows API.

    If you are satisfied with the solution(s) provided, please mark your thread as Solved.

    New quick method:
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

    Or you can use this way:

    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save

    Good luck.

    abousetta

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1