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

因为一旦点击呢个【X】。计算就中断了,我想把它禁用掉,这个能不能实现。。。。谢谢谢谢啦... 因为一旦点击呢个【X】。计算就中断了,我想把它禁用掉,这个能不能实现 。。。。谢谢谢谢啦 展开
 我来答
2724421
2011-04-27 · TA获得超过2493个赞
知道大有可为答主
回答量:1551
采纳率:71%
帮助的人:947万
展开全部
在你的用户窗口的代码中添加一个这个过程可以屏蔽VBA创建的用户窗口上标题栏的关闭按钮.但是要注意你的代码中要有能控制关闭该窗口的代码要不你没办法关闭这个用户窗口
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
Cancel = 1
End Sub
光浩晴n
2011-04-27
知道答主
回答量:46
采纳率:100%
帮助的人:29.1万
展开全部
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
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
沐o
2011-04-27 · TA获得超过117个赞
知道答主
回答量:32
采纳率:0%
帮助的人:31.5万
展开全部
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
虽然我也是在百度上找的,希望可以帮到你!
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
燕清me
2011-04-27
知道答主
回答量:47
采纳率:0%
帮助的人:28.2万
展开全部
那只是一个窗口关闭,是不是你安装有问题哟
追问
额。安装应该没有问题,用VBA编辑的那个东西,挺乱的。说不清楚。嘿嘿。,额。。
能把那个【X】隐藏或者禁用掉嘛,如果能。。希望能告诉我一下。。谢谢啦。。。。万分感谢
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(2)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式