如何在 Microsoft Word 中取消文本换行?

如何在 Microsoft Word 中取消文本换行?

我发现这个宏可以解包,但它解包了整个文档,而不仅仅是选定的文本。我该如何修改它以仅解包选定的文本?

 Sub pagebreaks()
'
' pagebreaks Macro
'
'
    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
        .Text = "^p^p"
        .Replacement.Text = "|"
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    With Selection.Find
        .Text = "^p"
        .Replacement.Text = " "
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    With Selection.Find
        .Text = "|"
        .Replacement.Text = "^p^p"
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
End Sub

答案1

“查找和替换”可以搜索换行符(看起来像反向的双“P”。例如在此处输入图片描述),然后只用空字符替换所有字符。只选择文本就可以了?不需要宏。

使用以下代码查找字母、格式、字段或特殊字符。请注意,某些代码仅在启用或禁用“使用通配符”选项时才有效。

在“查找内容”框或“替换为”框中可用的代码

查找:
段落标记 (段落标记

键入:
^p
(当启用“使用通配符”选项时,在“查找内容”框中不起作用),

或输入:
^13

或者仅通过选择文本反复查找然后删除(使用删除键)?

答案2

以下是可以起作用的宏:

  Sub pagebreaks()
    '
    ' pagebreaks Macro
    '
    '


With Selection.Find
        .ClearFormatting
        .Replacement.ClearFormatting
        .Text = "^p^p"
        .Replacement.Text = "|"
        .Forward = True
        .Wrap = wdFindStop
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
        .Execute Replace:=wdReplaceAll
End With

With Selection.Find
        .Text = "^p"
        .Replacement.Text = " "
        .Forward = True
        .Wrap = wdFindStop
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
        .Execute Replace:=wdReplaceAll
End With

With Selection.Find
        .Execute Replace:=wdReplaceAll
        .Text = "|"
        .Replacement.Text = "^p^p"
        .Forward = True
        .Wrap = wdFindStop
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
End With

With Selection.Find
        .Execute Replace:=wdReplaceAll
End With
End Sub

相关内容