Excel中经常需要使用到自动求和公式,自动求和具体该如何操作呢?接下来小编举例简单的例子告诉大家excel设置自动求和公式的方法。excel设置自动求和公式的方法设置自动求和公式步骤1:将鼠标放在要求和数据区域的紧挨着的下面一个单元格,如下图的D10单元格,然后点击【开始】-【自动求和】按钮就可以自动求D......
Excel VBA 窗体之去除窗体关闭按钮 实现代码
VBA的窗体缺少一般窗体的很多属性,不想许多语言窗体那样可以自由的设置窗体的样式,就连其默认的关闭按钮也不能设置为不显示,一般的处理方法是在窗体的关闭事件中添加代码来阻止窗体的关闭。那还不如就直接运用代码来把他去除掉(如图)。
附件下载:
点击链接从百度网盘下载
操作如下:
◾在Excel的VBE窗口中插入一个用户窗体,将其命名为frmNoCloseIcon。然后再添加一个模块。在窗体和模块中添加后面所列代码。
◾在工作薄中的任意工作表中添加一窗体按钮控件,将指定其设置宏为btnShowfrmMaxMin_Click。其供示范之用。
具体代码:
"mdClose"模块代码
Sub btnShowfrmMaxMin_Click()
frmNoCloseIcon.Show
End Sub
"frmNoCloseIcon" 窗体代码
'****************************************
'---此模块演示了去除窗体关闭按钮---
'****************************************
Option Explicit
'以下声明API函数
#If Win64 Then '64位
Private Declare PtrSafe Function FindWindow _
Lib "user32" _
Alias "FindWindowA" ( _
ByVal lpClassName As String, _
ByVal lpWindowName As String) _
As LongPtr
Private Declare PtrSafe Function GetWindowLong _
Lib "user32" _
Alias "GetWindowLongPtrA" ( _
ByVal hwnd As LongPtr, _
ByVal nIndex As Long) _
As LongPtr
Private Declare PtrSafe Function SetWindowLong _
Lib "user32" _
Alias "SetWindowLongPtrA" ( _
ByVal hwnd As LongPtr, _
ByVal nIndex As Long, _
ByVal dwNewLong As LongPtr) _
As LongPtr
Private Declare PtrSafe Function DrawMenuBar _
Lib "user32"( _
ByVal hwnd As LongPtr) _
As Long
#Else '32位
'查找窗口
Private Declare Function FindWindow _
Lib "User32" _
Alias "FindWindowA" ( _
ByVal lpClassName As String, _
ByVal lpWindowName As String) _
As Long
'取得窗口样式位
Private Declare Function GetWindowLong _
Lib "User32" _
Alias "GetWindowLongA" ( _
ByVal Hwnd As Long, _
ByVal nIndex As Long) _
As Long
'设置窗口样式位
Private Declare Function SetWindowLong _
Lib "User32" _
Alias "SetWindowLongA" ( _
ByVal Hwnd As Long, _
ByVal nIndex As Long, _
ByVal dwNewLong As Long) _
As Long
'重绘窗体标题栏
Private Declare Function DrawMenuBar _
Lib "User32" ( _
ByVal Hwnd As Long) _
As Long
#End If
#If Win64 Then '64位
Private FHwnd As LongPtr
Private FIstype As LongPtr
#Else
Private FHwnd As Long
Private FIstype As Long
#End If
'以下定义常数
Private Const GWL_STYLE = (-16) '窗口样式
Private Const WS_SYSMENU = &H80000 '系统菜单
Private Sub btnClose_Click()
Unload Me
End Sub
Private Sub btnReset_Click()
'取得窗口样式位
FIstype = GetWindowLong(FHwnd, GWL_STYLE)
'窗体样式位: 原样式和系统菜单
FIstype = FIstype Or WS_SYSMENU
'重设窗体样式位
SetWindowLong FHwnd, GWL_STYLE, FIstype
'重绘窗体标题栏
DrawMenuBar FHwnd
End Sub
'**************************************
'---------------主程序-----------------
'**************************************
Private Sub UserForm_Initialize()
'查找窗口句柄
FHwnd = FindWindow("ThunderDFrame", Me.Caption)
'取得窗口样式位
FIstype = GetWindowLong(FHwnd, GWL_STYLE)
'窗体样式位: 原样式和无系统菜单
FIstype = FIstype And Not WS_SYSMENU
'重设窗体样式位
SetWindowLong FHwnd, GWL_STYLE, FIstype
'重绘窗体标题栏
DrawMenuBar FHwnd
End Sub
相关文章