VBA TIPS
Making a title form with an Userform : With NO title bar

As usual, an userform has a title bar like this. When I would like to use an userform as a title form, I don't need a title bar. Also I want the userform to disappear automatically 3 seconds later.



Regarding to the back ground picture, you can set the picture what you like with using Picture property



In this case I use the following API(Application Program Interface) functions. Make an userform named Userform1 and give this code a try.

'///place these procedures on a standard module
Option Explicit

Public Const GWL_STYLE = -16
Public Const WS_CAPTION = &HC00000
Public Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" ( _
                                                                           ByVal hWnd As Long, _
                                                                           ByVal nIndex As LongAs Long
Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" ( _
                                                                           ByVal hWnd As Long, _
                                                                           ByVal nIndex As Long, _
                                                                           ByVal dwNewLong As LongAs Long
Public Declare Function DrawMenuBar Lib "user32" ( _
                                                  ByVal hWnd As LongAs Long
Public Declare Function FindWindowA Lib "user32" (ByVal lpClassName As String, _
                                                  ByVal lpWindowName As StringAs Long


Sub Form_Show()
    'Hide Excel
    Application.Visible = False
    'To close a form automatically
    Application.OnTime Now, "Form_Close"
    UserForm1.Show
End Sub


Sub Form_Close()
     'To close a form automatically
    Dim datWaitTime As Date
    datWaitTime = TimeSerial(Hour(Now()), Minute(Now()), Second(Now()) + 3)
    Application.Wait datWaitTime
    Unload UserForm1
    Application.Visible = True
End Sub


Sub HideTitleBar(frm As Object)
    Dim lngWindow As Long
    Dim lFrmHdl As Long
    lFrmHdl = FindWindowA(vbNullString, frm.Caption)
    lngWindow = GetWindowLong(lFrmHdl, GWL_STYLE)
    lngWindow = lngWindow And (Not WS_CAPTION)
    Call SetWindowLong(lFrmHdl, GWL_STYLE, lngWindow)
    Call DrawMenuBar(lFrmHdl)
End Sub


'//Place these procedures on the UserForm1 module
Option Explicit


Private Sub UserForm_Initialize()
    HideTitleBar Me
End Sub


Private Sub UserForm_Click()
'Close this userform
    Unload Me
End Sub



So the title bar will not be displaied and this form will be closed 3 seconds later automatically. Also Users can close this form with clicking on form.


| HOME |
Copyright © cellmasters.net - colo's junk room All Right Reserved
ABOUT
WORKS
THE CELL MASTERS
CONTACT
LINKS
Tips and Information about Microsoft Excel|Masaru Kaji aka Colo