简体   繁体   English

如何在 MS-Word 中删除不同格式的段落标记

[英]How to remove paragraph marks with different format in MS-Word

I have some lines that are separated by paragraph marks, but actually they belong to the same paragraph.我有一些由段落标记分隔的行,但实际上它们属于同一段落。

The issue is the text is in Arial 15, italic, but some words are not italic (shown in red) and the paragraph marks are Arial 15 italic, not italic and even Calibri 11. This means, not all paragraph mark have the same format.问题是文本是 Arial 15,斜体,但有些单词不是斜体(显示为红色),段落标记是 Arial 15 斜体,不是斜体,甚至是 Calibri 11。这意味着,并非所有段落标记都具有相同的格式.

I want to replace the paragraph marks with a space " " in order to join the lines in a single paragraph only for those group of continues lines that are Arial, 15 italic even though thet have not italic within them.我想将段落标记替换为空格“”,以便将单个段落中的行连接到仅用于 Arial、15 斜体的连续行组的单个段落中,即使它们在其中没有斜体。

I tried so far:我到目前为止尝试过:

Find what: ^p (with format: Arial 15, Italic) Replace with: " "查找内容:^p(格式:Arial 15,斜体)替换为:“”

But doing this only finds the paragraph mark shown in green.但是这样做只会找到以绿色显示的段落标记。

Below the image of input format and what I'm trying to get as output.在输入格式的图像下方以及我试图作为输出获得的内容。 Additionally I attach a sample file Sample.docx .此外,我附上了一个示例文件Sample.docx

示例图像 Thanks for any help谢谢你的帮助

Try尝试

Option Explicit
Sub ReplacePara()
Dim Para As Paragraph, Xstr As String, Rng As Range
Dim i As Long, ln As Long
Dim PrvChrSize As Integer, NextChrSize  As Integer
Dim PrvChrFont As String, NextChrFont  As String
Dim PrvChrItalic As Boolean, NextChrItalic As Boolean

    With ActiveDocument
    For i = .Paragraphs.Count To 1 Step -1
    Set Para = .Paragraphs(i)
    ln = Para.Range.Characters.Count

        If ln > 1 Then
            With Para.Range.Characters(ln - 1).Font
            PrvChrSize = .Size
            PrvChrFont = .Name
            PrvChrItalic = .Italic
            End With

            If i < .Paragraphs.Count Then
                With .Paragraphs(i + 1).Range.Characters(1).Font
                NextChrSize = .Size
                NextChrFont = .Name
                NextChrItalic = .Italic
                End With
            Else
            NextChrSize = 0
            NextChrFont = ""
            NextChrItalic = False
            End If
        End If

        Debug.Print i, PrvChrSize, PrvChrFont, NextChrSize, NextChrFont
        If (PrvChrSize = 15 And (PrvChrFont = "Arial" Or PrvChrItalic = True)) _
        And (NextChrSize = 15 And (NextChrFont = "Arial" Or NextChrItalic)) Then
        Para.Range.Characters(ln).Text = " "
        End If
    Next
  End With

End Sub

Result from sample file:示例文件的结果:

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM