Excel 中的列表框操作,可以很有序地实现选择功能,本文将介绍一个对象,以实现对列表框的新建、删除等操作 。

文章插图
ControlFormat对象可以通过Shape对象的ControlFormat属性返回 。
如下代码:
Set xListObj = Shapes(2).ControlFormat
xListObj就是一个ControlFormat对象 。
ControlFormat方法和属性
方法
属性
AddItem
Application
List
Creator
RemoveAllItems
DropDownLines
RemoveItem
Enabled
LargeChange
LinkedCell
ListCount
ListFillRange
ListIndex
LockedText
Max
Min
MultiSelect
Parent
PrintObject
SmallChange
Value

文章插图
如上图所示,本示例实现多种方法给ListBox控件添加列表值 。
首先新建一个列表框,代码如下:
PrivateSub AddListBox()'新建ListBox列表框DimxShape As ObjectSetxShape = Me.Shapes.AddFormControl(xlListBox, 100, 100, 210, 280)SetxShape = NothingEndSub 利用Additem 方法添加列表值
Private Sub AddListItems() '添加列表值 On Error Resume Next Dim xShape As Object Dim xListObj As Object SetxListObj = Shapes(2).ControlFormat WithxListObj .RemoveAllItems .AddItem "列表1".AddItem "列表2".AddItem "列表3"EndWithSetxListObj = NothingSetxShape = NothingEndSub

文章插图
List方法添加列表值
Private Sub AddListItems() '添加列表值 On Error Resume Next Dim xShape As Object Dim xListObj As Object SetxListObj = Shapes(2).ControlFormat xListObj.List = Array("eee", "dddd", "fff") SetxListObj = NothingSetxShape = NothingEndSub ListFillRange属性设置列表值
PrivateSub AddlistRange()'添加列表值OnError Resume NextDimxShape As ObjectDimxListObj As ObjectSetxListObj = Shapes(2).ControlFormatxListObj.ListFillRange= "B3:B10"SetxListObj = NothingSetxShape = NothingistFillRangeEndSub 删除列表值
PrivateSub DelListItems()'删除列表值OnError Resume NextDimxShape As ObjectDimxListObj As ObjectSetxListObj = Shapes(2).ControlFormatWithxListObj.RemoveItem.ListIndexEndWithSetxListObj = NothingSetxShape = NothingEndSub【附:所有代码大全及语法 vba编程代码大全】 ListBox列表框在编写种类功能性应用时,非常方便,熟练掌握可大大提高对Excel表格的自动化应用技巧 。
推荐阅读
- 新手vba基础入门教程指南 vba编程代码大全
- ipad所有型号和尺寸对照表 怎么看ipad是几代
- 1分钟解读苹果12手机所有参数配置 苹果12手机分辨率是多少
- 所有藏宝图的位置介绍 天国拯救鸽子笼下的宝藏在哪里
- 一文介绍lol所有英雄 英雄联盟lol人物图片大全和介绍
- 分享9个免费java开源代码网站 java源代码网站大全
- 火影忍者代码大全可复制 火影忍者究极冲击金手指代码
- 苹果手机微信恢复功能操作详解 苹果自带微信恢复代码
- html自动跳转代码大全 最新好看的html跳转网页源码
- 超全超细微信恢复聊天记录方法 苹果自带微信恢复代码