简体   繁体   English

组合框(窗体控件)VBA的默认值

[英]Default value of Combobox(form control) VBA

Hey I have been searching a lot on the internet but I haven't been able to find the solution. 嘿,我在Internet上搜索了很多东西,但是找不到解决方案。 I have atleast 10-15 combobox(form control) in my workbook. 我的工作簿中至少有10-15个组合框(窗体控件)。 I want them to display a default value of say "Select type". 我希望他们显示“选择类型”的默认值。 Now, I have tried doing this using the ".listindex" but then it doesn't allow me to change the value in the combobox(as the default is set permanently). 现在,我尝试使用“ .listindex”进行此操作,但是它不允许我更改组合框中的值(因为默认值是永久设置的)。

Can someone help? 有人可以帮忙吗? This is what I tried to use 这就是我尝试使用的

With ws(1).shapes("Chill1").controlformat
 .listindex = 1
End with

The default state of the Combobox would be blank, so if anything needs to be put in, it'll usually be an item from the list range. 组合框的默认状态为空白,因此,如果需要添加任何内容,通常是列表范围内的一项。

eg the input range (from Properties) is 例如,输入范围(来自“属性”)为

    A1:A10

and the cell link is 和单元格链接是

    B1

Then B1 can be manually or through a macro (workbook_open event) set to value: 1 然后,可以手动设置B1或通过宏(workbook_open事件)将其设置为值1:

    Private Sub Workbook_Open()
        Worksheets("Sheet1").Range("B1") = 1
    End Sub

and A1 can contain the string 'Select Type' 和A1可以包含字符串“选择类型”

That way everytime the workbook is opened, the macro sets the 1st values of each of these lists to "Select Type" 这样,每次打开工作簿时,宏都会将每个列表的第一个值设置为“选择类型”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM