vba - Excel 2003, adding content with checkboxes -
i propulating range rows using vba, each row have own checkbox.
so far code looks this:
dim objcolumnheadings range, objdbsheet worksheet dim lngrow long, objcell range dim objcheckbox object set objdbsheet = getdbsheet() set objcolumnheadings = objdbsheet.range("columnheadings") objcolumnheadings.clearcontents lngrow = 1 each varexisting in objcolumns objcolumnheadings.cells(lngrow, 1).value = varexisting set objcell = objcolumnheadings.cells(lngrow, 2) set objcheckbox = activesheet.oleobjects.add(classtype:="forms.checkbox.1" _ , left:=412.8 _ , top:=objcell.top _ , height:=10 _ , width:=9.6) objcheckbox.name = "cb" & lngrow objcheckbox.appearance.caption = "" objcheckbox.appearance.backcolor = &h808080 objcheckbox.appearance.backstyle = 0 lngrow = lngrow + 1 if lngrow > 1 exit end if next
setting name of checkbox works, setting other properties not , results in run-time error: '438', object doesn't support property or method.
when @ properties of newly added checkboxes name set correctly, caption, backcolor , backstyle not set.
how set these programatically?
use msforms.checkbox
, , set object
in it, that's easier. use following example code.
sub test() dim objcheckbox msforms.checkbox set objcheckbox = activesheet.oleobjects.add(classtype:="forms.checkbox.1" _ , left:=10.8 _ , top:=10 _ , height:=25 _ , width:=200).object objcheckbox.name = "dummy_test" objcheckbox.caption = "test" objcheckbox.backcolor = vbred objcheckbox.backstyle = 0 end sub
Comments
Post a Comment