VBA插入托架返回大胆和不折叠文本之间的返回



我有一个Word文档,它是面试的转录。主持人的评论是大胆的,受访者的评论并不大胆。这是大胆和未折的文字的漫长连续运行。我需要添加一个马车返回,以便主持人和受访者之间的问题之间存在空白。我找到了下面的代码,以在特定文本之间插入运输返回,但是我不知道如何更改它以在粗体和未折叠文本之间插入。任何帮助都非常感谢!

Sub Test()
    ActiveDocument.Paragraphs(1).Range.Text = "Foo" & Chr(11) & "Bar"
End Sub

这是我提出的,它使用一个子来插入大胆文本后的断点,然后呼叫另一个子来对非Bold文本进行相同的操作。我使用了代表视觉基本马车返回线的常数" vbcrlf",它等于chr(13) chr(10),我相信这是在文档中插入线路休息时的最佳兼容性实践chr(11)。

Sub InsertBreakAfterBold()
    'Select entire document
    Selection.WholeStory
    'Make each .Method belong to Selection.Find for readability
    With Selection.Find
        'Set search criteria for bold font
        .Font.Bold = True
        'Find next occurrence
        .Execute
        'Each time bold text is found add a line break to the end of it then find the next one
        Do While .Found
            Selection.Text = Selection.Text + vbCrLf
            .Execute
        Loop
    End With
    'Repeat process for nonbold text
    Call InsertBreakAfterNonbold
End Sub
Sub InsertBreakAfterNonbold()
    Selection.WholeStory
    With Selection.Find
        .Font.Bold = False
        .Execute
        Do While .Found
            Selection.Text = Selection.Text + vbCrLf
            .Execute 
        Loop
    End With
End Sub

Microsoft的VBA参考是我最大的资源:

最新更新