Jan 12th, 2006, 11:32 AM
#1
Thread Starter
New Member
[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
Jan 12th, 2006, 11:36 AM
#2
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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
Jan 12th, 2006, 11:39 AM
#3
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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
Jan 12th, 2006, 11:47 AM
#4
Thread Starter
New Member
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?
Jan 12th, 2006, 11:49 AM
#5
Re: VBA form losing focus(activewindow) when minimizing Excel
Try...
VB Code:
Sub OpenDailyOpsForm()
Application.WindowState = xlMinimized
frmDailyOps.Show
frmDailyOps.SetFocus
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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
Jan 12th, 2006, 12:18 PM
#6
Thread Starter
New Member
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.
Jan 12th, 2006, 12:31 PM
#7
Re: VBA form losing focus(activewindow) when minimizing Excel
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.
Jan 12th, 2006, 12:52 PM
#8
Thread Starter
New Member
Re: VBA form losing focus(activewindow) when minimizing Excel
I now have a generic form of the program ready for posting. Just attached it.
Jan 12th, 2006, 12:54 PM
#9
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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
Jan 12th, 2006, 12:56 PM
#10
Thread Starter
New Member
Re: VBA form losing focus(activewindow) when minimizing Excel
Now I attached it. The password for the spreadsheet commandbutton is left blank.
Attached Files
Jan 12th, 2006, 01:31 PM
#11
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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
Jan 12th, 2006, 01:46 PM
#12
Thread Starter
New Member
Re: VBA form losing focus(activewindow) when minimizing Excel
I just got it to work with:
VB Code:
Sub OpenDailyOpsForm()
'Application.WindowState = xlMinimized
Application.Workbooks.Parent.Visible = False
frmDailyOps.Show
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 .
Jan 12th, 2006, 02:03 PM
#13
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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
Jan 12th, 2006, 02:25 PM
#14
Thread Starter
New Member
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
Forum Rules
Click Here to Expand Forum to Full Width