【发布时间】:2019-04-12 16:39:23
【问题描述】:
我是 VBA 新手,正在尝试将字符串从 Sub 传递给 Public Function(Sub 和 Public Function 在不同的模块中,但在同一个 Workbook 中),将字符串拆分为 Public Function 中的数组,然后将数组从 Public Function 传递回 Sub。
我已经搜索过 Stack Overflow 并尝试了几种不同的方法,但都没有奏效。以下是我目前拥有的代码,它会产生以下错误:
运行时错误“9”: 下标超出范围
任何帮助将不胜感激。为基本问题道歉。谢谢。
子:
Sub export()
Dim testString As String
Dim testValue As Variant
'testString could have any number of values
testString = "TEST1, TEST2, TEST3, TEST4"
'Call the Public Function below
testValue = splitText(testValue)
End Sub
在另一个模块中调用以下公共函数:
Public Function splitText() As Variant
Dim testValue As Variant
'Trying to import testString from the Sub to split it
testValue = Split(testString, ",")
'Define result of the Public Function
splitText = testValue
End Function
【问题讨论】: