Close UserForm Event Intercept using word 2000

C

constance

Hi everybody,

i'd like to know if there is a possibility first of all to intercept
the event "close the userform window using the close button on the top
right side" ?

Second, is it possible to disable this action so the user can't close
the window as he wants, he needs to use the buttons I put in my forms
?

hope this is clear and don't hesitate to tell me if it's not

Thanx
Constance
 
J

JGM

Hi Constance,

Put the following code in the declaration section of the userform code page:
_______________________________________
Private Declare Function _
GetSystemMenu Lib "user32" _
(ByVal hwnd As Long, _
ByVal bRevert As Long) As Long

Private Declare Function _
GetMenuItemCount Lib "user32" _
(ByVal hMenu 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 Declare Function _
GetActiveWindow Lib _
"user32" () As Long

Const MF_BYPOSITION = &H400&
Const MF_REMOVE = &H1000&
_______________________________________

Then use the following in the userform_Activate event:
_______________________________________
Private Sub UserForm_Activate()
Dim hSysMenu As Long
Dim nCnt As Long
Dim lWin

lWin = GetActiveWindow()
hSysMenu = GetSystemMenu(lWin, False)
Stop
If hSysMenu Then
nCnt = GetMenuItemCount(hSysMenu)
If nCnt Then
RemoveMenu hSysMenu, nCnt - 1, _
MF_BYPOSITION Or MF_REMOVE
RemoveMenu hSysMenu, nCnt - 2, _
MF_BYPOSITION Or MF_REMOVE
DrawMenuBar lWin
End If
End If
End Sub
_______________________________________

That should do the trick... It does for me!

HTH
Cheers!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top