【发布时间】:2019-09-17 08:11:01
【问题描述】:
我设置了多个Worksheet对象,只设置了最后一个对象Nothing,第一个X是empty
多行声明正在工作
Dim ws1, ws2 As Worksheet
If ws1 is nothing then
If ws1 = "" then
If ws1 = "Empty" then
If ws1 = vbEmpty then
If IsEmpty(ws1) then
If IsNull(ws1) then
'tried all of these but get
'runtime error
If ws2 is nothing then
'works fine
Dim ws1 As Worksheet, ws2 As Worksheet
If ws1 is nothing then
'works fine
If ws2 is nothing then
'works fine
因Pᴇʜ的回答而跟进:
Dim ws1, ws2 As Worksheet
If ws1 Is Nothing Or IsEmpty(ws1) then
'runtime error
If IsEmpty(ws1) then
'works fine
If ws2 Is Nothing then
'works fine
运行时错误 424
我只是想通过多行声明使代码更干净,也许这是不可能的
结论: 我们必须分别声明每个变量! 第一个答案中的更多详细信息
【问题讨论】:
标签: excel vba object worksheet