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宏不能运行!

 

转载于:https://www.cnblogs.com/wxb-km/p/5212101.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值