excel vba 编程,怎么讲窗口右上角的那个【X】隐藏掉。。。或者把它的功能禁用,望各路大侠,多多帮助。

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了excel vba 编程,怎么讲窗口右上角的那个【X】隐藏掉。。。或者把它的功能禁用,望各路大侠,多多帮助。相关的知识,希望对你有一定的参考价值。

因为一旦点击呢个【X】。计算就中断了,我想把它禁用掉,这个能不能实现 。。。。谢谢谢谢啦

在你的用户窗口的代码中添加一个这个过程可以屏蔽VBA创建的用户窗口上标题栏的关闭按钮.但是要注意你的代码中要有能控制关闭该窗口的代码要不你没办法关闭这个用户窗口
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
Cancel = 1
End Sub
参考技术A 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
参考技术B 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
虽然我也是在百度上找的,希望可以帮到你!
参考技术C 那只是一个窗口关闭,是不是你安装有问题哟追问

额。安装应该没有问题,用VBA编辑的那个东西,挺乱的。说不清楚。嘿嘿。,额。。
能把那个【X】隐藏或者禁用掉嘛,如果能。。希望能告诉我一下。。谢谢啦。。。。万分感谢

怎么去掉窗口右上角的关闭按钮的图标?就是将窗口角上的那个“X”消掉,但是按钮还可以用

参考技术A 这个基本是不可能做到的,除非你有修改微软系统源代码的能力.或许有的主题会改到那里吧,我没试过,

以上是关于excel vba 编程,怎么讲窗口右上角的那个【X】隐藏掉。。。或者把它的功能禁用,望各路大侠,多多帮助。的主要内容,如果未能解决你的问题,请参考以下文章

怎么用vba给excel 加密

每打开一个excel表格 都会自动弹出一个book1的空表格 怎么解决?

Excel VBA如何遍历所有活动窗口

Excel VBA入门: 代码调试/错误处理/代码优化

我在excel中使用VBA宏程序时,报错无法执行,为啥!前提,程序没有问题,因为单位机器运行良好

求问:excel VBA对一个已经打开的网页进行操作