VoG™

  Les 20:56 05 Mar 03
Locked

Could you help me please.

Many yars ago I used to program in VB2 and, if I wanted a form I could get it without the bar at the top - is this possible in VBA?

  VoG™ 22:45 05 Mar 03

Yes it is

The first step is to create a class module. Name the class module "cTitleBarHider" and put the following code in it:

Private Declare Function FindWindow Lib "USER32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long

Private Declare Function GetWindowLong Lib "USER32" Alias "GetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long) As Long

Private Declare Function SetWindowLong Lib "USER32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long

Private Declare Function DrawMenuBar Lib "USER32" (ByVal hWnd As Long) As Long


Private Const GWL_STYLE As Long = (-16)

Private Const WS_CAPTION As Long = &HC00000

Public Property Set Form(oForm As Object)

Dim iStyle As Long

Dim hWndForm As Long

If Val(Application.Version) < 9 Then

'XL97

hWndForm = FindWindow("ThunderXFrame", oForm.Caption)

Else

'XL2000

hWndForm = FindWindow("ThunderDFrame", oForm.Caption)

End If

iStyle = GetWindowLong(hWndForm, GWL_STYLE)


iStyle = iStyle And Not WS_CAPTION

SetWindowLong hWndForm, GWL_STYLE, iStyle

DrawMenuBar hWndForm

End Property


Then, in the code module of any userform you wish to be titleless, put the following code:


Dim oTitleBarHider As New cTitleBarHider

Private Sub UserForm_Activate()

Set oTitleBarHider.Form = Me

End Sub

Lastly, change the userform's border style property to 1-fmBorderStyleSingle in the userform's property box. This will improve the appearance of the userform when it is displayed.

When the form is displayed, the UserForm_Activate procedure will run and in turn run the code in the class module which hides the title bar.


======================

The above is taken from Visual Basic Macro Examples from click here


I should add (1) I have not tried this myself and (2) anybody interested in VB programming in Excel - beginner or expert - would be well advised to get this plus click here


Finally it is very flattering that you have called me up by name but there are other Excel people on here like Whisperer and Cherria to name only two.

  Les 23:27 05 Mar 03

VoG™ - such is the price of fame :-)) When I had this problem your name immediately sprang to mind
- so many times have I seen your non-de-plume answering queries on VBA! Many thanks for the links and solution.

To Whisperer, Cherria (and anyone else) I apologise - no slight intended - your help is always appreciated

  Les 17:50 12 Mar 03

I have tried the code you so kindly posted for me - it did work and solved the problem I had. Again, many thanks.

  VoG™ 18:27 12 Mar 03

Glad to hear it worked.

This thread is now locked and can not be replied to.

How to get Windows 10 for free | How to install Windows 10: There is still a way to avoid paying…

1995-2015: How technology has changed the world in 20 years

Alex Chinneck’s giant ice cube Christmas tree at Kings Cross

Apple rumours & predictions 2017: The iPhone 8, new iPads, and everything else you should expect fr7…