VBA:如何使Variant为空?

问题描述 投票:5回答:1

我有以下Variant:

Dim comboitems() As Variant

我在所有代码中使用的数组包含ComboBox控件的值。

在代码的某个点上,我需要清除/清空/ null comboitems()。我能怎么做?我尝试了以下所有选项但没有成功。

comboitems = ""
comboitems = Null
comboitems = Nothing
Set comboitems = ""
Set comboitems = Null
Set comboitems = Nothing
comboitems() = ""
comboitems() = Null
comboitems() = Nothing
Set comboitems() = ""
Set comboitems() = Null
Set comboitems() = Nothing

我得到的错误是这样的:

enter image description here

vba variant
1个回答
4
投票

对于变体数组,您可以使用erase命令清除它们。

Erase comboitems

这是一个方便的参考指南,用于处理vba中的数组:

https://excelmacromastery.com/excel-vba-array/

© www.soinside.com 2019 - 2024. All rights reserved.