0

我试图选择一行或多行,直到在文档开头找到空白/空行,这将是标题。使用宏记录器录制的宏使用 selection.movedownunit。不确定这里必须使用什么该行可以是一个或多个。WDLine,WDParagraph 根据计数参数进行选择(因为行数不是恒定的)。确实使用了 VBNullString,^P^P,("\Blank).empty 但会引发错误。

自动生成的代码是:

Sub SelectTillBlankLine()
    Selection.MoveDown Unit:=WDLine , Count:=4 , Extend:=wdExtend
    Selection.Style = WDStyleTitle

End Sub

感谢任何建议...

4

1 回答 1

3

In my opinion best option is to use .Find object in this situation. Try with this code (and check some comments below):

Sub SelectTillBlankLine()

    'as of current selection we search for anything with two consecutive paragraphs
    'the second one is empty
    Selection.Find.Execute "*^13^13", , , True

    'some correction of range- remove last paragraph from selection
    ActiveDocument.Range(Selection.Start, Selection.End - 1).Select

    'the rest of your code
    Selection.Style = WDStyleTitle

End Sub

Tried and tested for simple document.

于 2013-10-24T16:09:18.977 回答