![](/img/trans.png)
[英]Type mismatch error passing a string to a function from an array (in 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.