VBA TIPS
Keeping the location of an userform

The following code would keep the location of an userform, in other words, it prevents that users moves an userform.

Place the following in an userform module.


Option Explicit

Private Const MF_BYCOMMAND = &H0&
Private Const SC_MOVE = &HF010&
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
                        (ByVal lpClassName As StringByVal lpWindowName As StringAs Long
Private Declare Function GetSystemMenu Lib "user32" _
                         (ByVal hwnd As LongByVal bRevert As LongAs Long
Private Declare Function DeleteMenu Lib "user32" _
                         (ByVal hMenu As LongByVal nPosition As LongByVal wFlags As LongAs Long

Private Sub UserForm_Initialize()
    Dim hwnd As Long
    Dim hMenu As Long
    Dim ret As Long
    Dim sClass As String

    'Check the version of Excel
    If Int(Val(Application.Version)) > 8 Then
        'Excel 2000 and the later version
        sClass = "ThunderDFrame"
    Else
        'Excel 97
        sClass = "ThunderXFrame"
    End If

    hwnd = FindWindow(sClass, Me.Caption)
    hMenu = GetSystemMenu(hwnd, 0&)
    ret = DeleteMenu(hMenu, SC_MOVE, MF_BYCOMMAND)
End Sub



| 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