Совсем надежного способа нет (в случае открытия этого же документа возникнут проблемы), а так вот
- Option Explicit
- Private Declare Function RemoveMenu Lib "user32" (ByVal hMenu As Long, ByVal nPosition As Long, _
- ByVal wFlags As Long) As Long
- Private Declare Function GetSystemMenu Lib "user32" (ByVal hwnd As Long, ByVal bRevert As Long) As Long
- Private Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal lpClassName As String, _
- ByVal lpWindowName As String) 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 Const MF_BYPOSITION = &H400&
- Const MF_REMOVE = &H1000&
-
- Private Sub UserForm_Initialize()
- Dim lHwnd As Long, hSysMenu As Long, nCnt As Integer
- lHwnd = FindWindow("ThunderDFrame", UserForm1.Caption)
- Do While lHwnd = 0
- lHwnd = FindWindow("ThunderDFrame", UserForm1.Caption)
- DoEvents
- Loop
- hSysMenu = GetSystemMenu(lHwnd, False)
- 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
- End If
- End If
- End Sub
Или более просто способ, но не такой красивый))
- Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
- If CloseMode = vbFormControlMenu Then
- Cancel = 1
- MsgBox "Òàê çàêðûòü íåëüçÿ"
- End If
- End Sub
Ответить
|