2016年9月21日 星期三

0921

類別元件屋
函數第三架構
public function 函數名稱() as 資料型態
      [程式區塊]
      函數名稱=回傳變數(值)
end function

函數第四 架構
public function 函數名稱(byval a as Integer,byval b as Integer) as 資料型態
      [程式區塊]
      函數名稱=回傳變數(值)
end function


物件類別模組   ==從插入建立
Public Function fun1()
    MsgBox "函數架構之區塊"
End Function
Public Function fun2(ByVal a As Integer, ByVal b As Integer)
    MsgBox a + b
End Function

Public Function fun3() As Integer
    fun3 = 555
End Function

Public Function fun4(ByVal x As Integer, ByVal y As Integer) As Integer
    Dim total As Integer
 
    total = x + y
    fun4 = total
End Function


=================================================
呼叫 類別元件
Private Sub CommandButton1_Click()
   Dim com1 As New Ani1   建立實體元件
   com1.fun1
End Sub

Private Sub CommandButton2_Click()
    Dim com1 As New Ani1
    com1.fun2 a:=12, b:=45     有別於一般用法 com1.fun2(a,b)
End Sub

Private Sub CommandButton3_Click()
    Dim com1 As New Ani1
    Dim i As Integer
 
    i = com1.fun3
    MsgBox i
End Sub

Private Sub CommandButton4_Click()
    Dim com1 As New Ani1
    Dim sum As Integer
 
    sum = com1.fun4(22, 55)
    MsgBox sum
End Sub

http://www.cpearson.com/excel/classes.aspx

陣列
http://www.globaliconnect.com/excel/index.php?option=com_content&view=article&id=161:excel-vba-passing-arguments-to-procedures-parameter-arrays-paramarray&catid=79&Itemid=475
多重頁面

'use the With ... End With statement to refer to a Range object
With Worksheets("Sheet1").Range("A1")
'use the Value property of the Range object, to set the value for the range:
.Value = 11
'use the Name property, of the Range object, to set the range name:
.Name = "Score"
'use the Font Property of the Range object that returns a Font object, and then use the With ... End With statement to refer to the Font object
With .Font
'note that because you are using the With ... End With statement to refer to the Font object within the Range object, you will not refer to both the range or font objects below:
'use the Name property of the Font object to set the font name:
.Name = "Arial"
'use the Bold property of the Font object to set the font to bold:
.Bold = True
'use the Color property of the Font object to set the font color:
.Color = vbRed
End With
'use the Borders property of the Range object to return all four borders (Borders collection object), and then use the LineStyle property of the Borders object to add a double border:
.Borders.LineStyle = xlDouble

'the Clear Method of the Range object, clears the range (clears the contents, formulas and formatting):
.Clear
End With

Excel Objects Hierarchy
Application Object
Workbook Object
Worksheet Object
Range Object

沒有留言:

張貼留言