|
-
Feb 16th, 2006, 09:46 PM
#1
Thread Starter
Fanatic Member
[RESOLVED] Display Excel Userform in 'unfocused' state
Is it possible to display an Excel Userform such that is appears initially in a de-highlighted state? I'm not sure, but I think the term is 'focus'
I currently show a modeless userform triggered from the workbook open event but it always appears in a highlighted state.
VB Code:
Private Sub Workbook_Open()
OptionList.Show vbModeless 'appears in highlighted state
End Sub
Last edited by VBAhack; Feb 18th, 2006 at 09:08 PM.
-
Feb 16th, 2006, 10:39 PM
#2
Re: Display Excel Userform in 'unfocused' state
VB Code:
Private Sub Workbook_Open()
OptionList.Show vbModeless
Application.WindowState = xlMinimized
Application.WindowState = xlMaximized
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 
-
Feb 16th, 2006, 11:35 PM
#3
Thread Starter
Fanatic Member
Re: Display Excel Userform in 'unfocused' state
RobDog,
That's an interesting trick. Thanks!
-
Feb 17th, 2006, 01:12 AM
#4
Re: Display Excel Userform in 'unfocused' state
I know its very elegant but as long as your opening the file any flashing from it minimizing/maximizing will not be noticeable. 
You could also get fancy and use a couple of APIs to get the solution but more work then its worth unless your needing it to be inactive when showing a userform and not in combination of opening the file and showing the userform.
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 
-
Feb 18th, 2006, 11:07 AM
#5
Thread Starter
Fanatic Member
Re: Display Excel Userform in 'unfocused' state
Actually, the flashing is very noticeable. You can readily see the window being minimized, then maximized. If the API approach isn't too nasty I'd like to give it a try in the interest of elegance. Can you explain?
P.S. I want the Userform to be inactive all the time except when clicked.
Last edited by VBAhack; Feb 18th, 2006 at 04:46 PM.
-
Feb 18th, 2006, 06:31 PM
#6
Thread Starter
Fanatic Member
Re: Display Excel Userform in 'unfocused' state
Robdog,
I managed to develop a workaround that has inperceptable flickering, but it means creating another userform:
VB Code:
Private Sub Workbook_Open()
OptionList.Show vbModeless
UserForm1.Show vbModeless 'dummy userform
Unload UserForm1
End Sub
I'm still interested in the API approach if you could post an example or a link. Thanks!
-
Feb 18th, 2006, 07:14 PM
#7
Re: Display Excel Userform in 'unfocused' state
Ok, here it is. Just paste the code behind your userform and viola! 
VB Code:
Option Explicit
'Code written by RobDog888
'Behind your userform:
Private Declare Sub SetWindowPos Lib "User32" (ByVal hWnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, _
ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long)
Const SW_SHOWNORMAL As Long = 1
Const SW_SHOWMAXIMIZED As Long = 3
Const HWND_TOPMOST As Long = -1
Const HWND_NOTOPMOST As Long = -2
Const HWND_BOTTOM As Long = 1
Const SWP_NOSIZE As Long = &H1
Const SWP_NOMOVE As Long = &H2
Const SWP_NOACTIVATE As Long = &H10
Const SWP_SHOWWINDOW As Long = &H40
Private mbFirst As Boolean
Private Sub UserForm_Activate()
'Show the window if first time
If mbFirst = True Then
SetWindowPos Application.hWnd, HWND_BOTTOM, 0, 0, 0, 0, SWP_SHOWWINDOW Or SWP_NOMOVE Or SWP_NOSIZE
Else
mbFirst = False
End If
End Sub
Private Sub UserForm_Initialize()
mbFirst = True
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 
-
Feb 18th, 2006, 08:30 PM
#8
Thread Starter
Fanatic Member
Re: Display Excel Userform in 'unfocused' state
RobDog,
Brilliant! Thanks. I decided to condense things a bit:
VB Code:
Option Explicit
Private Declare Sub SetWindowPos Lib "User32" (ByVal hWnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, _
ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long)
Private mbFirst As Boolean
Private Sub UserForm_Activate()
'Show the window if first time
If mbFirst = True Then
SetWindowPos Application.hWnd, CLng(1), 0, 0, 0, 0, CLng(&H40) Or CLng(&H2) Or CLng(&H1)
Else
mbFirst = False
End If
End Sub
Private Sub UserForm_Initialize()
mbFirst = True
End Sub
-
Feb 18th, 2006, 08:35 PM
#9
Re: Display Excel Userform in 'unfocused' state
Thanks but using the consts for the parameters are a better method as you dont have to remember what they mean.
Also, if you just pass the consts with the "&" long designator and add the hex Ors its evevn shorter.
VB Code:
SetWindowPos Application.hWnd, 1&, 0, 0, 0, 0, 67&
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 
-
Feb 18th, 2006, 08:40 PM
#10
Thread Starter
Fanatic Member
Re: Display Excel Userform in 'unfocused' state
Understood. Most appreciated!
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
|