刚才的代码报错For Each Word In sentenceWords
这段代码报错是因为在VBA中,ForEach语句不能用于遍历句子中的单词。正确的语法应该是使用For循环来遍历句子中的单词。以下是一个示例代码:
Dim sentence As String
sentence = "This is a sentence."
Dim words() As String
words = Split(sentence, " ")
Dim word As Variant
For Each word In words
' 在此处处理每个单词的代码
Debug.Print word
Next word
在这个示例中,首先将句子分割成一个单词数组(使用Split函数和空格作为分隔符)。然后使用For Each循环遍历数组中的每个单词,并在循环中处理每个单词。你可以根据需要修改循环内的代码来执行你想要的操作。
原文地址: https://www.cveoy.top/t/topic/hCFR 著作权归作者所有。请勿转载和采集!