Delphi 运行Word VBA 宏 删除软回车

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Delphi 运行Word VBA 宏 删除软回车相关的知识,希望对你有一定的参考价值。

Sub 整理网页()
‘整理网页:删除软回车、删除空白段、使段落文字两端对齐
Selection.WholeStory
   
    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
        .Text = "?^l"
        .Replacement.Text = "^&^p"
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchByte = False
        .MatchAllWordForms = False
        .MatchSoundsLike = False
        .MatchWildcards = True
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
   
    With Selection.Find
        .Text = "^1^l"
        .Replacement.Text = "^&^p"
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
   
    With Selection.Find
        .Text = "^l"
        .Replacement.Text = ""
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
   
    With Selection.Find
        .Text = "^p^s"
        .Replacement.Text = "^p"
        .MatchWildcards = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
   
    With Selection.Find
        .Text = "^p^p"
        .Replacement.Text = "^p"
        .MatchWildcards = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
   
    With Selection.Find
        .Text = "^p^p^p"
        .Replacement.Text = "^p"
        .MatchWildcards = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
   
    With Selection.Find
        .Text = "^p^p^p"
        .Replacement.Text = "^p"
        .MatchWildcards = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
   
    With Selection.Find
        .Text = "^p^p"
        .Replacement.Text = "^p"
        .MatchWildcards = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
   
    With Selection.Find
        .Text = "^p^p"
        .Replacement.Text = "^p"
        .MatchWildcards = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
   
    With Selection.Find
        .Text = "^p^p^p"
        .Replacement.Text = "^p"
        .MatchWildcards = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
   
    With Selection.Find
        .Text = "^p^p"
        .Replacement.Text = "^p"
        .MatchWildcards = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
   
    With Selection.Find
        .Text = "^p^p"
        .Replacement.Text = "^p"
        .MatchWildcards = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
   
    With Selection.Find
        .Text = "^p^p"
        .Replacement.Text = "^p"
        .MatchWildcards = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    Selection.Paragraphs.Alignment = wdAlignParagraphJustify
End Sub

Delphi可以通过ole word的方式来运行宏:

WordDoc := WordApp.Documents.open(fileName:=fn, Revert:=true, Visible := True);
wordapp.Run( MacroName:=‘整理网页‘);

非常蹊跷的是,如果Visible := False,则word宏不能运行!

 

以上是关于Delphi 运行Word VBA 宏 删除软回车的主要内容,如果未能解决你的问题,请参考以下文章

以编程方式从 Word 2007 文档中提取宏 (VBA) 代码

如何删除Word中的软回车(向下的小箭头)

关于 word VBA的宏运行 输入文本的代码 急求 谢谢

使用word中的VBA宏删除它后面没有表的字符串

如何通过单击 Word 2010 复选框来运行 VBA 宏?

word批量删除换行符