我的代码运行正常,直到#34;如果c =""然后&#34 ;.此时出现运行时错误' -2147418113(8000ffff)':自动化错误。我已经放了一个On Error Resume Next语句来检查一切是否正确,如果我跳过这一行并且确实如此。我真的不明白这个错误意味着什么,而且我无法找到有关它的有用信息。有人能为这个问题带来光明吗?我试图改变"如果c =""然后" to"如果len(c.value)= 0那么" 但它会引发相同的错误。 AddresRawDataFile中的所有变量都定义为public(作为范围),并且它们被设置为名为PublicVariable的不同模块中的范围,每个过程都会调用它。
Private Sub CommandButton3_Ok_Click()
Dim MsgAlert As String
Dim MsgBoxAlert As Variant 'Message box for for many checks done below
Dim c As Variant 'Variable used in a for each structure
Dim AddressRawDataFile As Variant 'Array of variables with address in Box2_UPb_Options
'Code to assign values from Box2_UPb_Options to the related variables
AddressRawDataFile = Array(RawHg202Range, RawPb204Range, RawPb206Range, RawPb207Range, RawPb208Range, RawTh232Range, RawU238Range, _
RawHg202Header, RawPb204HeaderRange, RawPb206HeaderRange, RawPb207HeaderRange, RawPb208HeaderRange, RawTh232HeaderRange, _
RawU238HeaderRange)
'All of the above variables must not be = ""
For Each c In AddressRawDataFile
'On Error Resume Next
If c = "" Then
MsgBoxAlert = MsgBox("There are one or more addresses missing in Start-AND-Options sheet. " & _
"Please, check it.", vbOKOnly, "Missing Address")
Load Box2_UPb_Options
Box2_UPb_Options.MultiPage1.Value = 2
Box2_UPb_Options.Show
End If
Next
答案 0 :(得分:0)
由于名为RawHg202Range
等的项目实际上是Range
个对象,因此您应该使用Is Nothing
检查它们是否为空:
AddressRawDataFile = Array(RawHg202Range, RawPb204Range, RawPb206Range, RawPb207Range, RawPb208Range, RawTh232Range, RawU238Range, _
RawHg202Header, RawPb204HeaderRange, RawPb206HeaderRange, RawPb207HeaderRange, RawPb208HeaderRange, RawTh232HeaderRange, _
RawU238HeaderRange)
For Each c In AddressRawDataFile
If c Is Nothing Then