我有下面的代碼應該爲它旁邊的listobject中的每一行添加一個複選框。我想開發一個批准工具,它從數據庫加載數據並將其加載到listobject中。之後,我可以通過複選框批准或拒登數據並保存更改。由於listobject會有更改長度,所以需要通過代碼添加和刪除複選框。什麼類型的電子表格複選框在vba中?
所以這裏的代碼:
Sub Approval()
Dim i As Integer
Dim tbl As ListObject
Dim CBcollection As Collection
Dim CB As msforms.CheckBox ' THIS IS WRONG
Dim sht As Worksheet
Dim L As Double, T As Double, H As Double, W As Double
Dim rng As Range
Set sht = Tabelle1
Set tbl = sht.ListObjects("ApprovalTBL")
Set rng = tbl.Range(2, 1).Offset(0, -1)
W = 10
H = 10
L = rng.Left + rng.Width/2 - W/2
T = rng.Top + rng.Height/2 - H/2
For i = 1 To tbl.ListRows.Count
Set CB = sht.OLEObjects.Add(ClassType:="Forms.CheckBox.1", Link:=False, DisplayAsIcon:=False, Left:=L, Top:=T, Width:=W, Height:=H)
'the line before will give me an error 13 type missmatch
CBcollection.Add (CB)
Set rng = rng.Offset(-1, 0)
T = rng.Top + rng.Height/2 - H/2
Next i
End Sub
現在的問題:
什麼類型在一個正常的電子表格複選框?
我總是使用「Option Explicit」,我總是將我的變量調暗到正確的類型,我不想使用變體類型。
窗體控件或ActiveX控件? –