Hide or Disable the closebutton of a Userform 
Author Message
 Hide or Disable the closebutton of a Userform

HOW?????????????????


Mon, 02 Jun 2003 05:57:14 GMT  
 Hide or Disable the closebutton of a Userform
Hi Bj?rn,

Draw a checkbox on a userform and a commandbutton (to close the form)

Private Sub CheckBox1_Change()
  Me.CommandButton1.Visible = Me.CheckBox1
End Sub

Krgrds,
Perry



Quote:
> HOW?????????????????



Mon, 02 Jun 2003 06:16:04 GMT  
 Hide or Disable the closebutton of a Userform
Hi Borg,

Attachments are usually discouraged here, partly because of the risk of
viruses, partly because of the size of them, and hence the additional
download cost for those on metered local call access or metered internet
access.

To show the button as greyed out and disabled, use the following code in the
form. (This has been adapted to VBA from similar VB code posted by Randy
Birch at www.mvps.org/vbnet/

Option Explicit

Private Const MF_BYPOSITION = &H400
Private Const MF_REMOVE = &H1000

Private Declare Function DrawMenuBar Lib "user32" _
      (ByVal hwnd As Long) As Long

Private Declare Function GetMenuItemCount Lib "user32" _
      (ByVal hMenu As Long) As Long

Private Declare Function GetSystemMenu Lib "user32" _
      (ByVal hwnd As Long, _
       ByVal bRevert 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

Private Sub UserForm_Activate()

   Dim hMenu As Long
   Dim menuItemCount As Long
   Dim iWindowHandle As Long

   iWindowHandle = GetActiveWindow()

  'Obtain the handle to the form's system menu
   hMenu = GetSystemMenu(iWindowHandle, 0)

   If hMenu Then

     'Obtain the number of items in the menu
      menuItemCount = GetMenuItemCount(hMenu)

     'Remove the system menu Close menu item.
     'The menu item is 0-based, so the last
     'item on the menu is menuItemCount - 1
      Call RemoveMenu(hMenu, menuItemCount - 1, _
                      MF_REMOVE Or MF_BYPOSITION)

     'Remove the system menu separator line
      Call RemoveMenu(hMenu, menuItemCount - 2, _
                      MF_REMOVE Or MF_BYPOSITION)

     'Force a redraw of the menu. This
     'refreshes the titlebar, dimming the X
      Call DrawMenuBar(iWindowHandle)

   End If

End Sub

--
Regards
Jonathan West - Word MVP
MultiLinker - Automated generation of hyperlinks in Word
Conversion to PDF & HTML
http://www.multilinker.com
Word FAQs at http://www.multilinker.com/wordfaq
Please post any follow-up in the newsgroup. I do not reply to Word questions
by email


Quote:



> > Hi Bj?rn,

> > Draw a checkbox on a userform and a commandbutton (to close the form)

> > Private Sub CheckBox1_Change()
> >   Me.CommandButton1.Visible = Me.CheckBox1
> > End Sub

> > Krgrds,
> > Perry



> > > HOW?????????????????



Mon, 02 Jun 2003 21:13:43 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Disable closebutton

2. Disable the ControlBox (Window CloseButton)

3. Hide the TitleBar of a UserForm

4. Esc Key and UserForm Hide

5. Userform.hide won't work!

6. Userform Hide vs. Unload Me

7. Returning focus to Word from hidden Userform

8. macro for hiding page (using userform command button)

9. Disable or hide buttons on custom toolbar?

10. How hide menuitens like tools options or disable com-add ins button

11. Hide/show and enable/disable buttons

12. Hide/Disable Word 2000 Menu Bar

 

 
Powered by phpBB® Forum Software