我在這裏找到了一個題目幾乎相同的問題。 @KazimierzJawor發佈了一個解決方案(子)。我想要做的就是把他解到一個函數,將與通過單個值工作:Excel VBA功能 - 爲單元格中的每個單詞添加「+」,但有例外
Function AddPlus(word As String) As String
Dim tmpWords As Variant
Dim SkipWords As Variant
SkipWords = Array("в", "от", "под", "над", "за", "перед")
Dim i As Integer, j As Integer
Dim Final As String, boExclude As Boolean
tmpWords = Split(word.Value, " ")
For i = 0 To UBound(tmpWords)
For j = 0 To UBound(SkipWords)
If UCase(SkipWords(j)) = UCase(tmpWords(i)) Then
boExclude = True
Exit For
End If
Next j
If boExclude = False Then
Final = Final & "+" & tmpWords(i) & " "
Else
Final = Final & tmpWords(i) & " "
End If
boExclude = False
Next i
word = Left(Final, Len(Final) - 1)
Final = ""
End Function
不過這個功能在行拋出一個錯誤「無效的限定詞」
tmpWords = Split(word.Value, " ")
我知道這一定很容易,但我對VBA很陌生,並沒有想出如何解決這個問題。也許這裏有人可以幫助我?
'word'是一個字符串變量,它沒有像'.value'這樣的屬性,所以刪除它。 –
@AlexK。是的,我自己找到了。然而,該函數返回空值,無論什麼「字」傳入(西里爾)。我不明白爲什麼,因爲它應該工作(在這裏有另一個主題很好的工作) –