VBA函数返回stringtypes不匹配错误

我正在为Excel 2010编写一个macros的VBA。我觉得我缺less一些基本的理解。 我已经填充了一个string数组并遍历该数组中的内容。 该数组中的文本来自HTML格式的电子邮件消息,并具有不间断的空间负载。 我想删除这些和其他非打印字符,以便我的输出只包含文本。

For Each str In stringArr() CleanString (str) If Len(str) <> 0 Then Cells(Row + 1, 6 + index) = str index = index + 1 End If Next str 

CleanString()返回一个string作为返回types,但是str不会改变。 我试过了:

testString = cleanString(str)

这会导致types不匹配错误。 有什么build议么?

更多信息…

 Function cleanString(sInput As String) As String Dim sResult As String sResult = sInput sResult = Replace(sResult, Chr(10), "") sResult = Replace(sResult, Chr(13), "") sResult = Replace(sResult, Chr(9), "") sResult = Replace(sResult, ChrW(160), "") sResult = Replace(sResult, Chr(32), "") Trim$ (sResult) Application.WorksheetFunction.Clean (sInput) cleanString = sResult Exit Function End Function 

谢谢您的帮助。 问题在于指定cleanString()需要一个string。 将其更改为cleanString(作为Variant),意味着我可以:

str = cleanString(str)

感谢Variatus