PDA

View Full Version : Disable x in word document



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

fumei
12-17-2009, 09:42 AM
"I found some code but its intermittent and will not work when placed in workbook_open"

WorkBook_Open? This is the Word forum.

Will not work in an Open event? I do not know how it could. The code may be there, but once the file IS opened, the Open procedure is terminated. Thus, how could you invoke the "X" during the Open instructions?