VBA中的Excel下拉列表:“无法获取Worksheet类的DropDowns属性” [英] Excel dropdowns in VBA: "Unable to get the DropDowns property of the Worksheet class"

查看:1140
本文介绍了VBA中的Excel下拉列表:“无法获取Worksheet类的DropDowns属性”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个代码:

  Sub addDropdown(Name)
ActiveSheet.DropDowns.Add(74.25,60 ,188.25,87.75)。选择
设置n = ActiveSheet.DropDowns(Name)
如果不是(n不是)然后
ActiveSheet.DropDowns(Name).Delete
End If
选择
.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
/ pre>

哪些导致运行时错误1004:无法获取Worksheet类的DropDowns属性



我是VBA noob,那么为什么它指的是财产?根据对象浏览器DropDowns是一个函数(虽然后来没有.Add的消息。)



此外,我可以在添加后再访问这个确切的东西一些DropDowns。我只是没有得到它。



我想要做的是删除具有相同名称的任何预先存在的下拉列表。

解决方案

如果命名的下拉列表不存在,则需要处理错误

  
设置n = ActiveSheet.DropDowns(名称)
出现错误goto 0


I have this code:

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

Which results in "Runtime error 1004: Unable to get the DropDowns property of the Worksheet class"

I am a VBA noob, so why is it refering to a property? According to the Object Browser DropDowns is a function (although that doesnt rime with the .Add later on).

Also, I can access this exact thing later on after having added something to DropDowns. I just dont get it.

What I want to do, is to delete any pre-existing dropdown with the same name.

解决方案

You need to handle the error if the named Dropdown does not exist

on error resume next
Set n = ActiveSheet.DropDowns(Name)
on error goto 0

这篇关于VBA中的Excel下拉列表:“无法获取Worksheet类的DropDowns属性”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆