Tezzies
12-17-2009, 06:13 AM
Hello all,I have found lots of code for disableing the [X] (Close button) on a userform. I was wondering if anyone has some code for doing the same on the actual document. I found some code but its intermittent and will not work when placed in workbook_open.
Heres the intermittent code:-
Option Explicit
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 FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Const MF_BYPOSITION = &H400&
Private Sub Command1_Click()
Dim wnd&, hMenu&
wnd& = FindWindow("OpusApp", vbNullString)
hMenu& = GetSystemMenu(wnd&, 0&)
RemoveMenu hMenu&, 6, MF_BYPOSITION
RemoveMenu hMenu&, 5, MF_BYPOSITION
End Sub
Heres the intermittent code:-
Option Explicit
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 FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Const MF_BYPOSITION = &H400&
Private Sub Command1_Click()
Dim wnd&, hMenu&
wnd& = FindWindow("OpusApp", vbNullString)
hMenu& = GetSystemMenu(wnd&, 0&)
RemoveMenu hMenu&, 6, MF_BYPOSITION
RemoveMenu hMenu&, 5, MF_BYPOSITION
End Sub