View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
[email protected] gwoodby@gmail.com is offline
external usenet poster
 
Posts: 58
Default Please, help!!! How to keep userform from being moved?

On Nov 13, 11:29 am, boris wrote:
I can not find "movable" property for the form. So, how can i prevent user
from moving it around?
Thanks


*** Place this code In a User Form ***

Option Explicit

Private Sub UserForm_Initialize()

Call RemoveCaption(Me)

End Sub

*** Place this code In a Module ***

Option Explicit

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

Sub RemoveCaption(objForm As Object)

Dim lStyle As Long
Dim hMenu As Long
Dim mhWndForm As Long

If Val(Application.Version) < 9 Then
mhWndForm = FindWindow("ThunderXFrame", objForm.Caption) 'XL97
Else
mhWndForm = FindWindow("ThunderDFrame", objForm.Caption)
'XL2000+
End If
lStyle = GetWindowLong(mhWndForm, -16)
lStyle = lStyle And Not &HC00000
SetWindowLong mhWndForm, -16, lStyle
DrawMenuBar mhWndForm

End Sub

Sub ShowForm()

UserForm1.Show False

End Sub