View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
keepITcool keepITcool is offline
external usenet poster
 
Posts: 2,253
Default Prevent UserForm on top of a worksheet from being dragged around screen

Larry,

Following will create a non movable userform.

Option Explicit

Private Const MF_BYCOMMAND As Long = &H0&
Private Const SC_MOVE As Long = &HF010
Private Const SC_SEPARATOR As Long = &HF00F

'USER32
Private Declare Function FindWindow Lib "user32" Alias _
"FindWindowA" (ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long
Private Declare Function GetSystemMenu Lib "user32" ( _
ByVal hwnd As Long, ByVal bRevert As Long) As Long
Private Declare Function DrawMenuBar Lib "user32" ( _
ByVal hwnd As Long) As Long
Private Declare Function RemoveMenu Lib "user32" ( _
ByVal hMenu As Long, ByVal nPosition As Long, _
ByVal wFlags As Long) As Long


Private Sub UserForm_Activate()
lockPos
End Sub

Sub lockPos()
Dim hWndForm As Long, hSysMenu As Long, nCnt As Long

hWndForm = FindWindow(vbNullString, Me.Caption)
If hWndForm Then
hSysMenu = GetSystemMenu(hWndForm, False)

If hSysMenu Then
RemoveMenu hSysMenu, SC_MOVE, MF_BYCOMMAND
RemoveMenu hSysMenu, SC_SEPARATOR, MF_BYCOMMAND
DrawMenuBar hWndForm
End If
End If

End Sub





keepITcool

< email : keepitcool chello nl (with @ and .)
< homepage: http://members.chello.nl/keepitcool


"L Mehl" wrote:

Hello --

Is it possible to do this?

Dave Peterson suggested that Screenupdating should be turned on when
you showing the form.
This does not solve the problem.

Ivan Moala suggested that code selecting a Hidden sheet might be the
problem. My code does not include that.

Thanks for any help.

Larry Mehl