码迷,mamicode.com
首页 > 编程语言 > 详细

Delphi 运行Word VBA 宏 删除软回车

时间:2016-02-24 10:56:03      阅读:204      评论:0      收藏:0      [点我收藏+]

标签:

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 宏 删除软回车

标签:

原文地址:http://www.cnblogs.com/wxb-km/p/5212101.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!