+ Reply to Thread
Results 1 to 14 of 14

Minimize the userform and give focus to the immediate next window, when button is clicked

  1. #1
    Registered User
    Join Date
    05-09-2014
    MS-Off Ver
    Excel 2003
    Posts
    24

    Minimize the userform and give focus to the immediate next window, when button is clicked

    I currently have a small userform placed at the bottom right of the screen (with a command button on it) and this opens up on top of excel instances and other applications/windows and it is set so that you can't interact with anything except the userform.

    I wanted to minimize the userform and give focus to immediate next window (can be excel or non excel applications) for 10 seconds and then activate/show the userform back again, when the "Button 1" on the userform is clicked.

    I tried hiding the userform, but this doesn't give focus to the immediate next window. Below is the code

    Please Login or Register  to view this content.
    Can someone help me out with the code which does the below steps?? I googled for this, I could only find answers for adding minimize and maximize buttons to userform.

    When the button is clicked, it should perform

    Step a - Minimize the userform
    Step b - Give focus to the next immediate window behind the userform
    Step c - Wait for 10 seconds
    Step d - Bring back the userform its to state.

    - Captain Cool
    Last edited by Fotis1991; 05-10-2014 at 04:25 AM. Reason: use tags for your codes pls.

  2. #2
    Valued Forum Contributor
    Join Date
    09-01-2013
    Location
    Dallas, TX
    MS-Off Ver
    Excel 2010
    Posts
    324

    Re: Minimize the userform and give focus to the immediate next window, when button is clic

    You can name the windows or ap windows if you know them.


    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    Example

    Please Login or Register  to view this content.
    Last edited by playaller; 05-10-2014 at 06:28 AM.


    Shelton A.
    If Helpful, Add Reputaion!

  3. #3
    Registered User
    Join Date
    05-09-2014
    MS-Off Ver
    Excel 2003
    Posts
    24

    Re: Minimize the userform and give focus to the immediate next window, when button is clic

    Thanks Playaller, But the applications or App windows keeps on changing.

    Is there any other way so that we can give focus to the immediate next window?

    - Captain Cool

  4. #4
    Valued Forum Contributor
    Join Date
    09-01-2013
    Location
    Dallas, TX
    MS-Off Ver
    Excel 2010
    Posts
    324

    Re: Minimize the userform and give focus to the immediate next window, when button is clic

    Thats a hard one. I'll search for a workaround.


    Not what you need but may help:
    Alternatively you can try this:

    When the button is pressed the first time it will close the form and open a new one in vbmodeless mode and hide it so focus can be brought on the named window or you have time to select it yourself. Then it will pause for 10 second for interaction. After 10 seconds it will close the modeless and open the original form. You can capture data in between the switches.

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    05-09-2014
    MS-Off Ver
    Excel 2003
    Posts
    24

    Re: Minimize the userform and give focus to the immediate next window, when button is clic

    Hi Playaller,

    Reason for looking for the code that gives the focus to the immediate next window is to take the alt print screen of the activte window. Currently as my userform has the focus, when I click on the capture button, it takes the print screen of my userform alone. But I wanted to give the focus to the immediate next window and then take the print screen of it.

    I've attached the code that I'm currently working on. Please have a look.

    Do you think of any other alternate where I could get the print screen of the active window?

    Also, for the post that you replied - http://www.excelforum.com/excel-prog...-word-doc.html

    I tried applying your suggested code, but it does seems to be working. Can you please help me out even here!

    Thanks a lot for your help so far!


    - Captain Cool
    Attached Files Attached Files

  6. #6
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643
    * Deleted *
    Last edited by Norie; 05-10-2014 at 08:11 AM.
    If posting code please use code tags, see here.

  7. #7
    Registered User
    Join Date
    05-09-2014
    MS-Off Ver
    Excel 2003
    Posts
    24

    Re: Minimize the userform and give focus to the immediate next window, when button is clic

    * deleted *
    Last edited by CaptainCool; 05-10-2014 at 09:43 AM.

  8. #8
    Registered User
    Join Date
    05-09-2014
    MS-Off Ver
    Excel 2003
    Posts
    24

    Re: Minimize the userform and give focus to the immediate next window, when button is clic

    Is it possible to invoke ALT + TAB keys within VBA. I think it should be possible as can invoke 'Prt Scr' key. I'm not that great at code, can any one help me here!

    I wanted the below to happen when I click the capture button on my userframe.

    Step a - Minimize the userform >>> userframe.hide
    Step b - Give focus to the next immediate window behind the userform by invoking ALT + TAB keys here. Need help here!
    Step c - Wait for 10 seconds >>> pauseapp(10)
    Step d - Bring back the userform its to state >>> userframe.show

    - Captain Cool

  9. #9
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Minimize the userform and give focus to the immediate next window, when button is clic

    Hello CaptainCool,

    I have code that will add the minimize, restore, and close X button to a userform so it behaves like a normal window. Would you be interested in this option?
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  10. #10
    Registered User
    Join Date
    05-09-2014
    MS-Off Ver
    Excel 2003
    Posts
    24

    Re: Minimize the userform and give focus to the immediate next window, when button is clic

    Though currently I'm trying to add keybd_event alt tab simulation to my code. I'm happy to take/go with any other option that works!

    - Caption Cool

  11. #11
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Minimize the userform and give focus to the immediate next window, when button is clic

    Hello CaptainCool,

    Step 1 of 2
    Add a new VBA Module to your workbook and paste this macro into it.
    Please Login or Register  to view this content.
    Step 2 of 2
    Add this code to your UserForm[/b]
    Please Login or Register  to view this content.

  12. #12
    Registered User
    Join Date
    05-09-2014
    MS-Off Ver
    Excel 2003
    Posts
    24

    Re: Minimize the userform and give focus to the immediate next window, when button is clic

    Hi Leith Ross,

    Your code is absolutely perfect! I could add minimize and restore button to my userform. Thanks for the code

    But my issue/question remains still open => give focus to the immediate next window, when button is clicked.

    I think I need to compromise on my question. :'(


    - Captain Cool

  13. #13
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Minimize the userform and give focus to the immediate next window, when button is clic

    Hello CaptainCool,

    Are you saying you have a command button on the UserForm when it is clicked should activate the next Window in the Z-Order? Or do you want the user to be able to select which application should be activated? Both cases are possible.

  14. #14
    Registered User
    Join Date
    05-09-2014
    MS-Off Ver
    Excel 2003
    Posts
    24

    Re: Minimize the userform and give focus to the immediate next window, when button is clic

    Hi Leith Ross,

    Attached is the Excel that I'm working on.. Main intention of the Userform's in this workbook is to capture the screen shot of the active window (which I'm not able to do)!

    Let me explain you the steps that I wanted to do...

    a. Open the workbook, Userform FrameOne pops up and ask for a Start. Once the user clicks Start, FrameOne will be hidden and FrameTwo will be shown.
    b. FrameTwo has two button - Capture and Stop. FrameTwo is designed in such a way that it sits on top of all the windows (as it is/should a Modeless frame).
    c. Lets assume that I'm working some multiple applications, not sure which one are those - May be Office application or Non Office applications. And I wanted to capture the ALT Print Screen of a particular window/app. As my userform is not top of it, I'll click the 'Capture' button which should capture the screenshot after giving the focus to other window that I'm working on.

    Here's the problem! I'm not able to capture screen shot of the active window. Below is my code and as in the attached workbook.

    Please Login or Register  to view this content.
    Kindly help me out as you said you can give the focus to window into both A Order and Z order.


    - Captain Cool
    Attached Files Attached Files
    Last edited by CaptainCool; 05-10-2014 at 11:43 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Userform Minimize Button Code Blocking Focus for First TextBox in Frame
    By excelforumkeys in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-14-2014, 12:57 PM
  2. How to minimize the Excel window while the Macro is running ?
    By Ndt in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-03-2013, 03:56 PM
  3. Minimize userform and application window
    By dubbdan in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-03-2013, 04:55 PM
  4. [SOLVED] Macro causing my window to minimize when clicked?
    By Bobp84 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-31-2012, 11:17 AM
  5. Minimize workbook window
    By mqdias in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-21-2007, 10:44 AM

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