如何在word文档中的某个页面/行之后应用宏?

时间:2014-04-06 18:20:21

标签: vba word-vba

我创建了一个宏,并希望将其应用于某个页面或右侧的文本中。在下图中显示了如何应用宏,它将来自第2页,然后是红线,文本将被粘贴在红线之后。

提前感谢帮助。

这是按钮代码:

Private Sub CommandButton1_Click()
Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
        .Text = ".^p"
        .Replacement.Text = "!teste!"
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    With Selection.Find
        .Text = "^p"
        .Replacement.Text = " "
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    With Selection.Find
        .Text = "!teste!"
        .Replacement.Text = ".^p"
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
End Sub

Private Sub CommandButton2_Click()
Selection.WholeStory
    Selection.ParagraphFormat.Alignment = wdAlignParagraphJustify
    With Selection.ParagraphFormat
        .SpaceBeforeAuto = False
        .SpaceAfterAuto = False
        .FirstLineIndent = CentimetersToPoints(1.25)
    End With
End Sub

enter image description here

0 个答案:

没有答案