- 帖子
- 4901
- 主題
- 44
- 精華
- 24
- 積分
- 4916
- 點名
- 166
- 作業系統
- Windows 7
- 軟體版本
- Office 20xx
- 閱讀權限
- 150
- 性別
- 男
- 來自
- 台北
- 註冊時間
- 2010-4-30
- 最後登錄
- 2025-7-10
               
|
回復 7# rick4615
實在不清楚你的需求為何?
是依據勾選欄位新增到清單內容嗎?- Sub Add_Check() '新增CheckBox
- With Sheet1
- For Each a In .Range(.[A3], .[A3].End(xlToRight))
- With .OLEObjects.Add(ClassType:="Forms.CheckBox.1", Left:=a.Left, Top:=.[A10].Top, Width:=a.Width, Height:=20)
- .Object.Caption = a
- End With
- Next
- End With
- End Sub
- Sub Add_ComboList() '依選取欄位,新增下拉清單內容
- Dim Ct As OLEObject, Ay()
- With Sheet1
- For Each Ct In .OLEObjects
- If Ct.progID = "Forms.CheckBox.1" Then '物件為CheckBox
- If Ct.Object.Value = True Then 'CheckBox被勾選
- Set a = .Rows(3).Find(Ct.Object.Caption, lookat:=xlWhole) '找到欄位
- ar = Application.Transpose(.Range(a, a.End(xlDown))) '欄位向下讀入陣列
- ReDim Preserve Ay(s) '擴充陣列大小
- Ay(s) = ar
- s = s + 1
- End If
- End If
- Next
- With .ComboBox1
- .Clear '清除清單
- .List = Application.Transpose(Ay) '將陣列寫入清單
- .ColumnCount = s '清單顯示欄位數量
- .Width = 80 * s '物件寬度
- End With
- End With
- End Sub
複製代碼 |
|