对于以下代码,Excel报告“UngültigerBezeichner”(无效标识符)。它抱怨的是Select Case parts.Length
。它抱怨parts
。有什么想法吗?
Public Sub parseFileName(fName As String, ByRef art As String, ByRef objnr As String, ByRef phase As String, ByRef index As String, ByRef text As String, ByRef warning As Boolean)
Dim parts() As String
parts = Split(fName, ".")
parts = Split(fName, parts(0))
warning = False
Select Case parts.Length
Case Is < 5 ' not a valid filename, do nohting
Return
Case 5 ' old style file name
art = part(0)
objnr = part(1)
text = part(2)
index = part(4)
Case 6 ' new stype file name
art = part(0)
phase = part(1)
objnr = part(2)
text = part(3)
index = part(5)
Case Is > 6 ' user used _ in text, do what we can and issue warning
art = part(0)
phase = part(1)
objnr = part(2)
text = part(3)
index = part(5)
warning = True
End Select
End Sub
答案 0 :(得分:3)
在VBA中确定数组的长度:
Dim arrLength as Integer
arrLength = UBound(parts) - LBound(parts) + 1