发布网友 发布时间:2022-04-22 09:28
共1个回答
热心网友 时间:2023-10-27 04:15
Private Declare Function SetWindowLong Lib "user32.dll" _
Alias "SetWindowLongA" ( _
ByVal hWnd As Long, _
ByVal nIndex As Long, _
ByVal dwNewLong As Long) _
As Long
Private Declare Function GetWindowLong Lib "user32.dll" _
Alias "GetWindowLongA" ( _
ByVal hWnd As Long, _
ByVal nIndex As Long) _
As Long
Private Declare Function SetWindowPos Lib "user32.dll" ( _
ByVal hWnd As Long, _
ByVal hWndInsertAfter As Long, _
ByVal x As Long, _
ByVal y As Long, _
ByVal cx As Long, _
ByVal cy As Long, _
ByVal wFlags As Long) _
As Long
Private Declare Function FindWindowEx Lib "user32.dll" _
Alias "FindWindowExA" ( _
ByVal hWnd1 As Long, _
ByVal hWnd2 As Long, _
ByVal lpsz1 As String, _
ByVal lpsz2 As String) _
As Long
Private Declare Function GetWindowThreadProcessId Lib "user32.dll" ( _
ByVal hWnd As Long, _
ByRef lpdwProcessId As Long) _
As Long
Private Declare Function SendMessage Lib "user32.dll" _
Alias "SendMessageA" ( _
ByVal hWnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
ByVal lParam As Long) _
As Long
Private Declare Function ExtractIcon Lib "shell32.dll" _
Alias "ExtractIconA" ( _
ByVal hInst As Long, _
ByVal lpszExeFileName As String, _
ByVal nIconIndex As Long) _
As Long
Private Declare Function GetCurrentProcessId Lib "kernel32.dll" () _
As Long
Private Declare Function GetDesktopWindow Lib "user32.dll" () _
As Long
Private Const GWL_STYLE As Long = (-16)
Private Const WS_MAXIMIZEBOX As Long = &H10000
Private Const WS_MINIMIZEBOX As Long = &H20000
Private Const WS_SYSMENU As Long = &H80000
Private Const HWND_TOP As Long = 0
Private Const SWP_NOMOVE As Long = &H2
Private Const SWP_NOSIZE As Long = &H1
Private Const SWP_FRAMECHANGED As Long = &H20
Private Const SWP_DRAWFRAME As Long = &H20
Private Const WM_SETICON As Long = &H80
'‘*****************************
Private Function FindOurWindow(Optional ByVal sClass As String = vbNullString, _
Optional ByVal sCaption As String = vbNullString)
Dim hWndDesktop As Long
Dim hWnd As Long
Dim hProcThis As Long
Dim hProcWindow As Long
hWndDesktop = GetDesktopWindow
hProcThis = GetCurrentProcessId
Do
hWnd = FindWindowEx(hWndDesktop, hWnd, sClass, sCaption)
GetWindowThreadProcessId hWnd, hProcWindow
Loop Until hProcWindow = hProcThis Or hWnd = 0
FindOurWindow = hWnd
End Function
'‘*****************************
Private Function ApphWnd() As Long
If Val(Application.Version) >= 10 Then
ApphWnd = Application.hWnd
Else
ApphWnd = FindOurWindow("XLMAIN", Application.Caption)
End If
End Function
'‘*****************************
Private Sub HasSystemMenu(ByVal Allow As Boolean)
Dim lStyle As Long: lStyle = GetWindowLong(ApphWnd, GWL_STYLE)
If Allow Then
lStyle = lStyle Or WS_SYSMENU
Else
lStyle = lStyle And Not WS_SYSMENU
End If
Call SetWindowLong(ApphWnd, GWL_STYLE, lStyle)
Call SetWindowPos(ApphWnd, HWND_TOP, 0, 0, 0, 0, _
SWP_NOMOVE Or SWP_NOSIZE Or SWP_DRAWFRAME)
End Sub
'‘*****************************
Public Sub RemoveX()
HasSystemMenu False '移除工作簿左上角图标和右上角最小化/最大化/关闭按钮
RemoveWindowX '移除工作表左上角图标和右上角最小化/最大化/关闭按钮
End Sub
'‘*****************************
Public Sub RestoreX()
HasSystemMenu True '恢复工作簿左上角图标和右上角最小化/最大化/关闭按钮
RestoreWindowX '恢复工作表左上角图标和右上角最小化/最大化/关闭按钮
End Sub
'‘*****************************
Public Sub RemoveWindowX()
ActiveWorkbook.Protect , , True
End Sub
'‘*****************************
Public Sub RestoreWindowX()
ActiveWorkbook.Protect , , False
End Sub
插入一模块,然后把上述代码复制过去.,执行宏RemoveX即可去除最大最小化按钮追问首先,谢谢你的回答.
但我用的是EXCEL2010,只有 RemoveWindowX 这一句起作用,使工作表上的三个按钮消失. HasSystemMenu False 这一句不起作用,不知为什么?
请给指点迷经,不胜感激.
追答啊,我没有2010的版本.,只有2003和2007,我都测试过,可以的.
你F8单步执行看看有什么提示么,试试是什么问题,
不然我也不知道了.