Why is Selection.Find not returning all results in Word VBA?

扶醉桌前 提交于 2019-12-24 08:57:10

问题


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

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.

What could cause this?


回答1:


In VBA + is not used for concatenation. You have to replace it with &

Change Text = Text + Selection to Text = Text & Selection and try again. I have tested it and it works...



来源:https://stackoverflow.com/questions/11318016/why-is-selection-find-not-returning-all-results-in-word-vba

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!