English 中文(简体)
微软W. VBA——如何整理重点强调的零散段落?
原标题:Microsoft Word VBA - how to condense fragmented paragraphs that are highlighted?

我正在尝试创建一个宏,用于查找我的Word文档中没有段落完整性的突出文本,并删除换行符以压缩文本。

例如,在以下形象中,我需要宏观转变:

将此翻译成中文:uncondensed img 无损压缩图像

对于此:

“entergraph

我对万国邮局说得很新,因此,我尝试了自己来做。

Sub CondenseZap()

 
  CondenseZap Macro
 
 

    Dim rngTemp As Range
 
    Set rngTemp = ActiveDocument.Range(Start:=0, End:=0)
    With rngTemp.Find
     .ClearFormatting
     .Highlight = True
     
     With CondenseRange.Find
            .Text = "^p"
            .Replacement.Text = " "
            .Execute Replace:=wdReplaceAll
        
            .Text = "  "
            .Replacement.Text = " "
            
            While InStr(CondenseRange.Text, "  ")
                .Execute Replace:=wdReplaceAll
            Wend
            
            If CondenseRange.Characters.Item(1).Text = " " And _
            CondenseRange.Paragraphs.Item(1).Range.Start = CondenseRange.Start Then _
            CondenseRange.Characters.Item(1).Delete
        End With
        
     End With
     
    End With
      
End Sub

这段代码没有执行,我不确定如何编写退出条件。我测试了一下,让程序识别所有带有突出显示的单词,只是我不确定如何在末尾替换每个断行符。

注意:我不想搞乱其他加粗文本之间的换行(BFS 9不应与“偿付能力”合并。只有突出部分)。

如果有人能帮我把这个组合起来,我会非常感激。

干杯。

问题回答

www.un.org/Depts/DGACM/index_spanish.htm 请更正如下:。

比较案文的最容易的方法是利用突出的条件:

Sub CondenseZap()
   
    Dim rngTemp As Range, ur As UndoRecord
 
    Rem do this, it only takes one step when undo
    Set ur = Word.Application.UndoRecord
    ur.StartCustomRecord "CondenseZap"
    Set rngTemp = ActiveDocument.Range
    
    With rngTemp.Find
        .ClearFormatting
        .Text = "^p"
        .Forward = True
        .Wrap = wdFindStop
        
        Do While .Execute()
            If rngTemp.Next Is Nothing Then Exit Do
                
            Rem 比较案文的最容易的方法是利用突出的条件: 3 = wdTurquoise
            If rngTemp.Previous.HighlightColorIndex = 3 And rngTemp.Next.HighlightColorIndex = 3 Then
                rngTemp.Text = " "
            End If
            
             reset the range
            rngTemp.SetRange rngTemp.End, rngTemp.Document.Range.End
        Loop
        
    End With

    ur.EndCustomRecord
    
End Sub

这是你想要的吗?如果是,请接受答案以关闭此问题。





相关问题
Handling no results for docmd.applyfilter

I have an Access app where I use search functionality. I have a TextBox and a Search Button on the form, and it does a wildcard search of whatever the user enters in the TextBox, and displays the ...

Outlook 2007 CommandBarControl.Execute won t work

I recently switched to Outlook 2007 and noticed that my VBA-macros won t work. I use the following code to open a new appointment-item (and fill it automatically). It worked perfect in Outlook 2003, ...

Connecting to Oracle 10g with ODBC from Excel VBA

The following code works. the connection opens fine but recordset.recordCount always returns -1 when there is data in the table. ANd If I try to call any methods/properties on recordset it crashes ...

MS Access: list macro from VBA

I have to deal with a few macros (not VBA) in an inherited Access application. In order to document them, I would like to print or list the actions in those macros, but I am very dissatisfied by ...

热门标签