python封装vba_VBA类模块封装
VBA類(lèi)模塊封裝
2018-09-26
"封裝宏-------------------------
Sub 表達(dá)式變公式()
Dim g As New 功能庫(kù)
g.公式變數(shù)值 Range("b3")
g.自定義格式變數(shù)值 Range("c3")
g.表達(dá)式變公式 Range("d3")
End Sub
Sub 刪除重復(fù)值()
Dim cc As New 功能庫(kù)
cc.刪除重復(fù)數(shù)據(jù) Selection
End Sub
"封裝自定義函數(shù)-------------------------
Sub 計(jì)算()
Dim f As New 函數(shù)庫(kù)
Debug.Print "和:" & f.求和(Range("a1:a5"))
Debug.Print "平均值:" & f.平均數(shù)(Range("a1:a5"))
Debug.Print "最大值:" & f.最大值(Range("a1:a5"))
End Sub
"類(lèi)模塊-------------------------
"窗體庫(kù)
"下面是增加最大化最小化按鈕聲明
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 FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function DrawMenuBar Lib "user32" (ByVal hWnd As Long) As Long
Private Const GWL_STYLE = (-16) ? ? ? ? ? ? ? ? "窗口樣式
Private Const WS_THICKFRAME = &H40000 ? ? ? ? ? "可更改大小
Private Const WS_MAXIMIZEBOX = &H10000
Private Const WS_MINIMIZEBOX = &H20000
"下面是去除窗體標(biāo)題的聲明
Private Const WS_CAPTION As Long = &HC00000
Dim hWnd, IStyle
Property Set 含最大最小按鈕的窗體(fm As MSForms.UserForm)
Dim hWnd As String, MyType As String
hWnd = FindWindow("ThunderDFrame", fm.Caption) ?"取得窗口句柄
MyType = GetWindowLong(hWnd, GWL_STYLE) ? ? ? ? "取得窗口樣式
MyType = MyType Or WS_THICKFRAME ? ? ? ? ? ? ? ?"重新設(shè)置窗口樣式
MyType = MyType Or WS_MAXIMIZEBOX ? ? ? ? ? ? ? "添加最大化按鈕
MyType = MyType Or WS_MINIMIZEBOX ? ? ? ? ? ? ? "添加最小化按鈕
SetWindowLong hWnd, GWL_STYLE, MyType ? ? ? ? ? "應(yīng)用樣式
DrawMenuBar (hWnd)
End Property
Property Set 無(wú)標(biāo)題窗體(frm As MSForms.UserForm)
hWnd = FindWindow("ThunderDFrame", frm.Caption) "獲取窗口句柄
IStyle = GetWindowLong(hWnd, GWL_STYLE)
IStyle = IStyle And Not WS_CAPTION
SetWindowLong hWnd, GWL_STYLE, IStyle
DrawMenuBar hWnd
End Property
"類(lèi)模塊-------------------------
"功能庫(kù)
Sub 公式變數(shù)值(rg As Range)
rg = rg.Value
End Sub
Sub 自定義格式變數(shù)值(rg As Range)
rg = rg.Text
End Sub
Sub 表達(dá)式變公式(rg As Range)
rg = "=" & rg.Value
End Sub
Sub 刪除重復(fù)數(shù)據(jù)(rg As Range)
Dim d As New Dictionary, x As Integer
Dim arr
arr = rg
For x = 1 To UBound(arr)
d(arr(x, 1)) = ""
Next x
rg.Clear
rg.Cells(1, 1).Resize(d.Count) = Application.Transpose(d.Keys)
End Sub
"類(lèi)模塊-------------------------
"函數(shù)庫(kù)
Function 求和(rg As Range)
求和 = Application.Sum(rg)
End Function
Function 平均數(shù)(rg As Range)
平均數(shù) = Application.Average(rg)
End Function
Function 最大值(rg As Range)
最大值 = Application.Max(rg)
End Function
免責(zé)聲明:本文僅代表文章作者的個(gè)人觀點(diǎn),與本站無(wú)關(guān)。其原創(chuàng)性、真實(shí)性以及文中陳述文字和內(nèi)容未經(jīng)本站證實(shí),對(duì)本文以及其中全部或者部分內(nèi)容文字的真實(shí)性、完整性和原創(chuàng)性本站不作任何保證或承諾,請(qǐng)讀者僅作參考,并自行核實(shí)相關(guān)內(nèi)容。
http://www.pinlue.com/style/images/nopic.gif
總結(jié)
以上是生活随笔為你收集整理的python封装vba_VBA类模块封装的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 内存检测方法
- 下一篇: EXCEL2016下将身份证号这列重复项