使用早期绑定和Microsoft Scripting Runtime Library创建字典对象时,看起来有两个相同的类型名称用于同一事物:
Dim dict as Dictionary
Set dict = New Dictionary
Run Code Online (Sandbox Code Playgroud)
和
Dim dict as Scripting.Dictionary
Set dict = new Scripting.Dictionary
Run Code Online (Sandbox Code Playgroud)
似乎做同样的事情(至少到目前为止).
我看到了这个资源As Scripting.Dictionary使用的语法,我看到了这个(非常好的)资源使用的语法,但我没有看到任何地方的比较.关于字典的MSDN文档要么是文字笑话,要么与VBA没有明确相关.As Dictionary
我不明白为什么我应该做额外的打字只是为了让我的函数声明更加拥挤,如果我可以使用As Dictionary,但我已经了解到VBA中看起来像它们相同的一些东西实际上可以有微妙但显着的差异(Application.InputBoxvs .InputBox例如).
这些之间是否真的没有区别,或者我应该注意哪些微妙的差异?
我正在尝试添加数据验证下拉列表,但我已经对其进行了一段时间的调试,但无济于事。我收到运行时错误 1004、应用程序定义或对象定义错误。该错误发生在Validation.Add语句的公式 1 设置部分。
我尝试使用对命名范围的字符串引用、对标准范围的字符串引用,以及如下所示的从工作表上的列表生成的逗号分隔列表字符串,如下面的代码所示。我已经检查了列表字符串Debug.Print并得到了预期的结果。
Sub addPT_Validation()
Dim sValidationList As String
Dim cell As Range
For Each cell In ThisWorkbook.Names("PT_Puldown").RefersToRange
sValidationList = sValidationList & cell.Value & ","
Next cell
sValidationList = Left(sValidationList, Len(sValidationList) - 1)
With ActiveSheet.Range("D14").Validation
.Add Type:=xlValidateList, _
AlertStyle:=xlValidAlertStop, _
Operator:=xlEqual, _
Formula1:=sValidationList
.IgnoreBlank = True
.InCellDropdown = True
.ShowError = True
End With
End Sub
Run Code Online (Sandbox Code Playgroud)
在此先感谢您的任何指导。