昱得資訊工作室
麻辣學園
歡迎光臨, 訪客. 請先 登入註冊一個帳號.
您忘了 啟用您的帳號嗎?
2009-01-07, 05:58:47
世界展望會助學計劃
首頁 說明 登入 註冊 贊助論壇 想當作者?
新聞: 會員注意!!麻辣家族討論區[通用版規],請詳閱!!


+  麻辣家族討論區
|-+  MS Office 系列
| |-+  EXCEL
| | |-+  Excel程式區 (版主: hsieh)
| | | |-+  VBA如何設定物件為陣列?
0 會員 以及 1 訪客 正在閱讀本篇主題. « 上一篇主題 下一篇主題 »
頁: [1] 向下 列印
作者 主題: VBA如何設定物件為陣列?  (閱讀 2383 次)
a0807121
訪客


電子郵件
VBA如何設定物件為陣列?
« 於: 2005-04-12, 10:30:33 »

我的表單上有33個按鈕
在VBA中可以將物件名稱設為陣列嗎?
如:Commandbuttin(0)~Commandbuttin(32)
謝謝!
已記錄
yem
高中生
*
離線 離線

文章: 110



Re: VBA如何設定物件為陣列?
« 回覆文章 #1 於: 2005-04-12, 11:07:19 »

我的表單上有33個按鈕
在VBA中可以將物件名稱設為陣列嗎?
如:Commandbuttin(0)~Commandbuttin(32)
謝謝!

物件名稱設為陣列?不大懂,是這樣嗎? Roll Eyes

Private Sub UserForm_Initialize()
    Dim ctl As MSForms.Control
    Dim Commandbuttin() As CommandButton
    Dim i%
    i = 1
    For Each ctl In Me.Controls
        '判斷是否為CommandButton
        If TypeName(ctl) = "CommandButton" Then
            ReDim Preserve Commandbuttin(1 To i)
            Set Commandbuttin(i) = ctl
            i = i + 1
        End If
    Next
End Sub
已記錄

What doesn't kill you will only make you stronger
leonchou
論壇維護群
*
離線 離線

文章: 1204


Re: VBA如何設定物件為陣列?
« 回覆文章 #2 於: 2005-04-13, 02:46:02 »

Dim Commandbutton As New Collection

Private Sub UserForm_Initialize()
' 加入 Commandbutton 集合
For Each ctl In Me.Controls
 If TypeName(ctl) = "CommandButton" Then
  Commandbutton.Add ctl
 End If
Next
End Sub

Private Sub CommandButton1_Click()
' 讀取 Commandbutton 集合
For i = 1 To Commandbutton.Count
Cells(i, 1) = Commandbutton(i).Name '應用Commandbutton的屬性
Next i
End Sub

相關參考
http://gb.twbts.com/index.php/topic,165.0.html
已記錄

頁: [1] 向上 列印 
« 上一篇主題 下一篇主題 »
自訂搜尋
跳到:  

本頁花了 0.238 秒, 以及 20 次的資料庫查詢.