gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 21:56:48 25 4
gpt4 key购买 nike

我正在为 Excel 2010 编写 VBA 中的宏。我觉得我的理解中缺少一些基本的东西。我已经填充了一个字符串数组并迭代了该数组中的内容。数组中的文本来自一个 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

关于string - VBA函数返回字符串类型不匹配错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42990860/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com