Private Sub SystemBGWorkBook_DeActive(ByVal Wn As Excel.Window) Handles SystemBGWorkBook.WindowDeactivate
pExcelApp.Cursor = Excel.XlMousePointer.xlDefault
End Sub
Private Sub SystemBGWorkBook_Close(ByRef Cancel As Boolean) Handles SystemBGWorkBook.BeforeClose
Cancel=true
End Sub
Private Sub WorkBook_Resize(ByVal Wb As Excel.Workbook, ByVal Wn As Excel.Window) Handles pExcelApp.WindowResize
Wn.WindowState = Excel.XlWindowState.xlMaximized
End Sub
Dim exl As Object
Set exl = CreateObject("Excel.Application")
count = exl.CommandBars.FindControls(ID:=18).count
For i = 1 To count
'屏蔽新建菜单
exl.CommandBars.FindControls(ID:=18).Item(i).Enabled = False
Next i
count = exl.CommandBars.FindControls(ID:=23).count
For i = 1 To count
'屏蔽打开菜单
exl.CommandBars.FindControls(ID:=23).Item(i).Enabled = False
Next i
count = exl.CommandBars.FindControls(ID:=3).count
For i = 1 To count
'屏蔽保存菜单
exl.CommandBars.FindControls(ID:=3).Item(i).Enabled = False
Next i
count = exl.CommandBars.FindControls(ID:=797).count
For i = 1 To count
'屏蔽自定义菜单
exl.CommandBars.FindControls(ID:=797).Item(i).Enabled = False
Next i
count = exl.CommandBars.FindControls(ID:=522).count
For i = 1 To count
'屏蔽选项菜单
exl.CommandBars.FindControls(ID:=522).Item(i).Enabled = False
Next i
count = exl.CommandBars.FindControls(ID:=797).count
For i = 1 To count
'屏蔽退出菜单
exl.CommandBars.FindControls(ID:=797).Item(i).Enabled = False
Next i
可调用api函数,下面是函数声明和调用。
Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As Any, ByVal lpWindowName As Any) As Long
Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Global Const gwl_style = (-16)
Const sw_hide = 0
Const sw_shownormal = 1
Global Const ws_sysmenu = &H80000
Sub removecontrolmenu()
Dim windowstyle As Long
Dim hwnd As Long
Dim windowname As String
windowname = Application.Caption
hwnd = FindWindow(0&, ByVal windowname)
windowstyle = GetWindowLong(hwnd, gwl_style)
windowstyle = windowstyle And (Not ws_sysmenu)
result = SetWindowLong(hwnd, gwl_style, windowstyle)
End Sub
Sub restorecontrolmenu()
Dim windowstyle As Long
Dim hwnd As Long
Dim windowname As String
windowname = Application.Caption
hwnd = FindWindow(0&, ByVal windowname)
windowstyle = GetWindowLong(hwnd, gwl_style)
windowstyle = windowstyle Or ws_sysmenu
result = SetWindowLong(hwnd, gwl_style, windowstyle)
End Sub