为什么Selection.Find无法在Word VBA中返回所有结果? [英] Why is Selection.Find not returning all results in Word VBA?
问题描述
我正在尝试根据某些格式设置规则从文档中提取文本.字体大小等于10.5.这就是我现在正在做的事情:
I'm trying to extract text out of a document based on certain formatting rules, e.g. the font size equals 10.5. This is what I'm doing now:
Selection.Find.Font.Size = 10.5
Text = ""
Do While Selection.Find.Execute = True
Text = Text + Selection
Loop
Debug.Print Text
它可以工作,但是由于某种原因,它似乎无法返回所有结果.当我进行手动搜索(即Ctrl + H)并使用相同的格式设置规则时,会返回更多结果.
It works, but for some reason it doesn't seems to return all results. When I do a manual search, i.e. Ctrl+H, and use the same formatting rule many more results are returned.
是什么原因造成的?
推荐答案
在VBA中,+
不用于串联.您必须将其替换为&
In VBA +
is not used for concatenation. You have to replace it with &
将Text = Text + Selection
更改为Text = Text & Selection
,然后重试.我已经对其进行了测试,并且可以正常工作...
Change Text = Text + Selection
to Text = Text & Selection
and try again. I have tested it and it works...
这篇关于为什么Selection.Find无法在Word VBA中返回所有结果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!