excel vba 编程,怎么讲窗口右上角的那个【X】隐藏掉。。。或者把它的功能禁用,望各路大侠,多多帮助。
展开全部
1> 在sheet1里面添加一个按钮,双击 ,添加以下代码
Private Sub CommandButton1_Click()
If CloseMode = 1 Then
CloseMode = 0
Sheets("sheet1").CommandButton1.Caption = "关闭按钮有效"
ElseIf CloseMode = 0 Then
CloseMode = 1
Sheets("sheet1").CommandButton1.Caption = "关闭按钮无效"
End If
End Sub
2> 在vba窗口的 ThisWorkBook中添加下面代码
Private Sub Workbook_BeforeClose(Cancel As Boolean)
If CloseMode <> 1 Then Cancel = True
End Sub
3> 插入一个模块,在模块中添加下面代码
Public CloseMode As Integer
Private Sub CommandButton1_Click()
If CloseMode = 1 Then
CloseMode = 0
Sheets("sheet1").CommandButton1.Caption = "关闭按钮有效"
ElseIf CloseMode = 0 Then
CloseMode = 1
Sheets("sheet1").CommandButton1.Caption = "关闭按钮无效"
End If
End Sub
2> 在vba窗口的 ThisWorkBook中添加下面代码
Private Sub Workbook_BeforeClose(Cancel As Boolean)
If CloseMode <> 1 Then Cancel = True
End Sub
3> 插入一个模块,在模块中添加下面代码
Public CloseMode As Integer
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
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即可去除最大最小化按钮
原自:http://zhidao.baidu.com/question/239794236.html
虽然我也是在百度上找的,希望可以帮到你!
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即可去除最大最小化按钮
原自:http://zhidao.baidu.com/question/239794236.html
虽然我也是在百度上找的,希望可以帮到你!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
那只是一个窗口关闭,是不是你安装有问题哟
追问
额。安装应该没有问题,用VBA编辑的那个东西,挺乱的。说不清楚。嘿嘿。,额。。
能把那个【X】隐藏或者禁用掉嘛,如果能。。希望能告诉我一下。。谢谢啦。。。。万分感谢
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询