Userform without caption, border, close button (I'm not craz

RogerC

Well-known Member
Joined
Mar 25, 2002
Messages
536
Is it possible to make a userform that has no border or caption bar? I found some code provided by Colo that removes the X button, but I need to hide the borders and caption also. Believe it or not, I have a perfectly sane reason for wanting to do this!
vogel.gif
 
OK Richard

Try this cut down version.

<PRE>
<FONT color=#008000>'***************************************************************************
</FONT>
<FONT color=#008000>'*
</FONT>
<FONT color=#008000>'* AUTHOR: STEPHEN BULLEN, Business Modelling Solutions Ltd.
</FONT>
<FONT color=#008000>'* TIM CLEM
</FONT>
<FONT color=#008000>'*
</FONT>
<FONT color=#008000>'* CONTACT: Stephen@BMSLtd.co.uk
</FONT>
<FONT color=#008000>'* WEB SITE: http://www.BMSLtd.co.uk
</FONT>
<FONT color=#008000>'*
</FONT>
<FONT color=#008000>'* DESCRIPTION: Makes a userform Borderless
</FONT>
<FONT color=#008000>'*
</FONT>
<FONT color=#008000>'* THIS MODULE:
</FONT>
<FONT color=#008000>'*
</FONT>
<FONT color=#008000>'* PROCEDURES:
</FONT>
<FONT color=#008000>'* UserForm_Activate Handles above
</FONT>
<FONT color=#008000>'*
</FONT>
<FONT color=#008000>'* Amended: for RichardC by Ivan F Moala 02 Jan 2003
</FONT>
<FONT color=#008000>'***************************************************************************
</FONT>


<FONT color=blue>Option Explicit</FONT>

<FONT color=#008000>'Windows API calls to do all the dirty work!
</FONT>
Private Declare <FONT color=blue>Function </FONT>FindWindow Lib "user32" _

Alias "FindWindowA" ( _

<FONT color=blue>ByVal</FONT> lpClassName <FONT color=blue>As</FONT><FONT color=blue> String</FONT>, _

<FONT color=blue>ByVal</FONT> lpWindowName <FONT color=blue>As</FONT><FONT color=blue> String</FONT>) <FONT color=blue>As</FONT><FONT color=blue> Long</FONT>

Private Declare <FONT color=blue>Function </FONT>GetWindowLong Lib "user32" _

Alias "GetWindowLongA" ( _

<FONT color=blue>ByVal</FONT> hWnd <FONT color=blue>As</FONT><FONT color=blue> Long</FONT>, _

<FONT color=blue>ByVal</FONT> nIndex <FONT color=blue>As</FONT><FONT color=blue> Long</FONT>) <FONT color=blue>As</FONT><FONT color=blue> Long</FONT>

Private Declare <FONT color=blue>Function </FONT>SetWindowLong Lib "user32" _

Alias "SetWindowLongA" ( _

<FONT color=blue>ByVal</FONT> hWnd <FONT color=blue>As</FONT><FONT color=blue> Long</FONT>, _

<FONT color=blue>ByVal</FONT> nIndex <FONT color=blue>As</FONT><FONT color=blue> Long</FONT>, _

<FONT color=blue>ByVal</FONT> dwNewLong <FONT color=blue>As</FONT><FONT color=blue> Long</FONT>) <FONT color=blue>As</FONT><FONT color=blue> Long</FONT>

Private Declare <FONT color=blue>Function </FONT>ShowWindow Lib "user32" ( _

<FONT color=blue>ByVal</FONT> hWnd <FONT color=blue>As</FONT><FONT color=blue> Long</FONT>, _

<FONT color=blue>ByVal</FONT> nCmdShow <FONT color=blue>As</FONT><FONT color=blue> Long</FONT>) <FONT color=blue>As</FONT><FONT color=blue> Long</FONT>

Private Declare <FONT color=blue>Function </FONT>DrawMenuBar Lib "user32" ( _

<FONT color=blue>ByVal</FONT> hWnd <FONT color=blue>As</FONT><FONT color=blue> Long</FONT>) <FONT color=blue>As</FONT><FONT color=blue> Long</FONT>

Private Declare <FONT color=blue>Function </FONT>SetFocus Lib "user32" ( _

<FONT color=blue>ByVal</FONT> hWnd <FONT color=blue>As</FONT><FONT color=blue> Long</FONT>) <FONT color=blue>As</FONT><FONT color=blue> Long</FONT>



<FONT color=#008000>'Lots of window styles for us to play with!
</FONT>
Private <FONT color=blue>Const </FONT>GWL_STYLE <FONT color=blue>As</FONT><FONT color=blue> Long</FONT> = (-16) <FONT color=#008000>'The offset of a window's style
</FONT>
Private <FONT color=blue>Const </FONT>GWL_EXSTYLE <FONT color=blue>As</FONT><FONT color=blue> Long</FONT> = (-20) <FONT color=#008000>'The offset of a window's extended style
</FONT>
Private <FONT color=blue>Const </FONT>WS_CAPTION <FONT color=blue>As</FONT><FONT color=blue> Long</FONT> = &HC00000 <FONT color=#008000>'Style to add a titlebar
</FONT>


Private <FONT color=blue>Const </FONT>WS_EX_DLGMODALFRAME <FONT color=blue>As</FONT><FONT color=blue> Long</FONT> = &H1 <FONT color=#008000>'Controls if the window has an icon
</FONT>


<FONT color=#008000>'Constant to identify the Close menu item
</FONT>
Private <FONT color=blue>Const </FONT>SC_CLOSE <FONT color=blue>As</FONT><FONT color=blue> Long</FONT> = &HF060



<FONT color=#008000>'Constants for hide or show a window
</FONT>
Private <FONT color=blue>Const </FONT>SW_SHOW <FONT color=blue>As</FONT><FONT color=blue> Long</FONT> = 5





<FONT color=blue>Private <FONT color=blue>Sub </FONT></FONT>UserForm_Activate()

<FONT color=blue>Dim </FONT>iStyle <FONT color=blue>As</FONT><FONT color=blue> Long</FONT>

<FONT color=blue>Dim </FONT>hWndForm <FONT color=blue>As</FONT><FONT color=blue> Long</FONT>



<FONT color=#008000> '// Amended use NullString for Version the userform's window handle
</FONT>
hWndForm = FindWindow(vbNullString, Me.Caption) <FONT color=#008000>'XL97
</FONT>
<FONT color=#008000> 'Else
</FONT>
<FONT color=#008000> ' hWndForm = FindWindow("ThunderDFrame", Me.Caption) 'XL2000
</FONT>
<FONT color=#008000> 'End If
</FONT>


iStyle = GetWindowLong(hWndForm, GWL_STYLE)



<FONT color=#008000> 'Build up the basic window style flags for the form
</FONT>
iStyle = iStyle And Not WS_CAPTION



<FONT color=#008000> 'Set the basic window styles
</FONT>
SetWindowLong hWndForm, GWL_STYLE, iStyle



iStyle = GetWindowLong(hWndForm, GWL_EXSTYLE)



<FONT color=#008000> 'Build up and set the extended window style
</FONT>
iStyle = iStyle And Not WS_EX_DLGMODALFRAME



SetWindowLong hWndForm, GWL_EXSTYLE, iStyle



<FONT color=#008000> 'Show the window with the changes
</FONT>
ShowWindow hWndForm, SW_SHOW

DrawMenuBar hWndForm

SetFocus hWndForm



<FONT color=blue>End Sub</FONT>


</PRE>
 
Upvote 0

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Nice one Ivan,

I looked at the extended Windows style in Dan Appleman's book but thought they weren't what we needed. I take my hat off to you sir :)
 
Upvote 0
Thanks Ivan. Unfortunately, using your new code I'm still getting a small frame around the edge of the Userform. Do you get a completely frameless form?
My Userform's BackColor property is set to black and I'm opening it on a worksheet that has a black background. This makes the border easy to see... the border is very small, but it's still there.

I noticed one thing different between the first code you modified and this latest modification... the appearance of the border is slightly changed. Using the first code the top/left edges of the Userform are white, bottom/right edges are grey. With the new code this is reversed, top/left are grey, bottom/right are white. I need them to be completely gone (in this case a completely black form edge-to-edge).

If this is working for you, can you tell me what I may be doing wrong?

Hi dk. Did Ivan's latest code completely remove the frame around the form for you?
This message was edited by RogerC on 2003-01-02 13:46
 
Upvote 0
Hi dk. Did Ivan's latest code completely remove the frame around the form for you?

Yes. I made my userform black, and my worksheet black. When I ran the userform I couldn't see anything. Let me know if you want a working workbook emailed to you.
 
Upvote 0
HHmmm? ...I wonder why I still get a border?

Yes! Would you please email me the file that worked for you? Thanks so much.
 
Upvote 0
On 2003-01-02 17:12, RogerC wrote:
HHmmm? ...I wonder why I still get a border?

Yes! Would you please email me the file that worked for you? Thanks so much.

Hi Richard
Yes I get NO frame or border ?
I have the UF initially set with NO BORDER
to start?
 
Upvote 0

Forum statistics

Threads
1,216,475
Messages
6,130,847
Members
449,599
Latest member
blakecintx

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top