VBA中的Excel下拉列表:“无法获取Worksheet类的DropDown属性”
我有这个代码:
Sub addDropdown(Name) ActiveSheet.DropDowns.Add(74.25, 60, 188.25, 87.75).Select Set n = ActiveSheet.DropDowns(Name) If Not (n Is Nothing) Then ActiveSheet.DropDowns(Name).Delete End If With Selection .ListFillRange = "$K$15:$M$19" .LinkedCell = "$K$8:$L$11" .DropDownLines = 6 .Display3DShading = False .Name = Name End With ActiveSheet.DropDowns(Name).Display3DShading = True End Sub
其结果是“运行时错误1004:无法获取Worksheet类的DropDowns属性”
我是一个VBA noob,为什么它涉及到一个属性? 根据对象浏览器的DropDown是一个函数(虽然这不与以后加。
另外,我可以在稍后添加DropDowns的东西后访问这个确切的东西。 我只是没有得到它。
我想要做的是删除任何已有的同名的下拉菜单。
如果指定的下拉列表不存在,则需要处理该错误
on error resume next Set n = ActiveSheet.DropDowns(Name) on error goto 0