拆分和 VBA.Split
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8190384/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Split and VBA.Split
提问by DevilWAH
Playing with excel and came up with this error
玩excel并提出这个错误
Sub Split()
Dim txt As String
Dim x As Variant
txt = Sheets("Raw").Cells(2, 2).Value
MsgBox (txt)
x = Split(txt, ",")
For Each i In x
MsgBox (i)
Next
Give me an error of two many arguments for the split function
给我一个 split 函数的两个多个参数的错误
however
然而
Sub Split()
Dim txt As String
Dim x As Variant
txt = Sheets("Raw").Cells(2, 2).Value
MsgBox (txt)
x = VBA.Split(txt, ",")
For Each i In x
MsgBox (i)
Next
works just fine?
工作正常吗?
So whats going on, I am sure i have used split before with out needing the vba. prefix?
所以发生了什么,我确定我之前使用过 split 而不需要 vba。字首?
Cheers
干杯
Aaron
亚伦
回答by Tim
Not real familiar with Excel VBA, but looking at the code snippet you posted I think the VBA interpreter may have gotten confused.
不太熟悉 Excel VBA,但查看您发布的代码片段,我认为 VBA 解释器可能会感到困惑。
You have Sub Split()
, and the code that follows is, I assume, for that function?
您有Sub Split()
,我假设接下来的代码是针对该功能的?
When it tried to execute Split(txt, ",")
, it most likely thought you were referring to your Split function, which takes no arguments, yet you were passing in two.
当它尝试 execute 时Split(txt, ",")
,它很可能认为你指的是你的 Split 函数,它不接受任何参数,但你传入了两个。
Using VBA.Split
resolved the reference confusion, because you're then telling it to use the Split method in the VBA namespace.
UsingVBA.Split
解决了引用混淆,因为您随后告诉它使用 VBA 命名空间中的 Split 方法。