繁体   English   中英

VBA函数返回字符串类型不匹配错误

[英]VBA Function Return string type mismatch error

我正在VBA for Excel 2010中编写一个宏。我觉得我在理解中遗漏了一些基本内容。 我填充了一个字符串数组并迭代该数组中的内容。 数组中的文本来自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()返回一个字符串作为返回类型,但str不会更改。 我试过了:

testString = cleanString(str)

这给出了类型不匹配错误。 有什么建议么?

更多信息...

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()需要一个字符串。 将它更改为cleanString(作为Variant),意味着我可以:

str = cleanString(str)

感谢Variatus

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM