Results 1 to 14 of 14

Thread: [RESOLVED] VBA form losing focus(activewindow) when minimizing Excel

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2006
    Posts
    7

    Resolved [RESOLVED] VBA form losing focus(activewindow) when minimizing Excel

    I know my first problem is i'm using VBA. However, with limited resources, this is what I need to use.

    What i have is a Excel spreadsheet being populated with a VBA form. When i load the form, i'm minimizing the spreadsheet. Due to minimizing the spreadsheet the form loses focus(opens up behind any other opened window) until i click on either the form or Excel's minimized application located in the windows taskbar.

    Is there a way to regain focus on the form? In VBA you cannot "hide" the spreadsheet, i have to minimize it. Thanks in advance.

    Joel
    Systems Analyst

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: VBA form losing focus(activewindow) when minimizing Excel

    Welcome to the Forums.

    Moved from Classic VB forum.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: VBA form losing focus(activewindow) when minimizing Excel

    Use Me.Setfocus right after your code to minimize Excel. Are you minimizing just the workbook or are you minimizing the Excel application itself?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  4. #4

    Thread Starter
    New Member
    Join Date
    Jan 2006
    Posts
    7

    Re: VBA form losing focus(activewindow) when minimizing Excel

    Thanks for responding so quickly. I am minimizing the application so the user does not see or have access to the spreadsheet. I am minimizing the application through a module

    Sub OpenDailyOpsForm()

    Application.WindowState = xlMinimized

    frmDailyOps.Show

    End Sub

    and I'm initializing the form through the form's code. It seems Windows handles the minimization of the application, making any other opened program the activewindow. Therefore, I have to either click on the minimized Excel in the taskbar or click on the form itself.

    Any suggestions?

  5. #5
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: VBA form losing focus(activewindow) when minimizing Excel

    Try...
    VB Code:
    1. Sub OpenDailyOpsForm()
    2.  
    3.     Application.WindowState = xlMinimized
    4.  
    5.     frmDailyOps.Show
    6.     frmDailyOps.SetFocus
    7.  
    8. End Sub
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  6. #6

    Thread Starter
    New Member
    Join Date
    Jan 2006
    Posts
    7

    Re: VBA form losing focus(activewindow) when minimizing Excel

    I've tried the me.setfocus in the module but that errors out since it's in a module and not in the form's code. I've also tried it in the form's initialize sub but it does not "activate the form". I've tried the frmDailyOps.setfocus in both the form's code and the module's code (after minimizing the application) and it does the same thing. I can email you the excel file, it's only 66kb in size, so you can see what I mean.

  7. #7
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: VBA form losing focus(activewindow) when minimizing Excel

    Quote Originally Posted by langej
    I can email you the excel file, it's only 66kb in size, so you can see what I mean.
    Or, you could just attach it to a thread post. and let anyone that wants to help out have a look.

  8. #8

    Thread Starter
    New Member
    Join Date
    Jan 2006
    Posts
    7

    Re: VBA form losing focus(activewindow) when minimizing Excel

    I now have a generic form of the program ready for posting. Just attached it.

  9. #9
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: VBA form losing focus(activewindow) when minimizing Excel

    Create a new post and before you submit it click on the Manage Attachments button new the bottom of the page.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  10. #10

    Thread Starter
    New Member
    Join Date
    Jan 2006
    Posts
    7

    Re: VBA form losing focus(activewindow) when minimizing Excel

    Now I attached it. The password for the spreadsheet commandbutton is left blank.
    Attached Files Attached Files

  11. #11
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: VBA form losing focus(activewindow) when minimizing Excel

    Here is the problem, your displaying the userform Modally. this is preventing any code after the .Show from running. If you show it modeless by setting the ShowModally property to false then it works ok.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  12. #12

    Thread Starter
    New Member
    Join Date
    Jan 2006
    Posts
    7

    Re: VBA form losing focus(activewindow) when minimizing Excel

    I just got it to work with:
    VB Code:
    1. Sub OpenDailyOpsForm()
    2.  
    3.     'Application.WindowState = xlMinimized
    4.     Application.Workbooks.Parent.Visible = False
    5.     frmDailyOps.Show
    6.  
    7. End Sub

    and to show the spreadsheet I used visible=true. Thanks guys for all your input. I just hope this solution doesn't cause problems down the road.

    What I find interesting in this solution is when you type in this line, after Parent, the .visible = false doen't show in the quickpics option window.
    Last edited by langej; Jan 12th, 2006 at 02:11 PM.

  13. #13
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: VBA form losing focus(activewindow) when minimizing Excel

    Yes, the minimize was causing the issue to.
    Glad its resolved now.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  14. #14

    Thread Starter
    New Member
    Join Date
    Jan 2006
    Posts
    7

    Re: VBA form losing focus(activewindow) when minimizing Excel

    Yah, I tried the modal property and it did work but it showed the spreadsheet too and that is what I didn't want. Thanks for looking at this issue.
    Joel

Posting Permissions

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



Click Here to Expand Forum to Full Width