【问题标题】:MS word macro vba For Each pageMS word 宏 vba For Each page
【发布时间】:2018-01-20 17:52:19
【问题描述】:

我的问题是我必须在 microsoft office word 中运行这个宏,它会在页面的开头和结尾插入一个矩形 现在,宏是用word注册的,如下。

Sub Macro1()
'
' Macro1 Macro
'
'
    ActiveDocument.Shapes.AddShape(msoShapeRectangle, 0#, -23.65, 634.05, _
        45.15).Select
    Selection.ShapeRange.ScaleHeight 1.14, msoFalse, msoScaleFromTopLeft
    ActiveWindow.ActivePane.VerticalPercentScrolled = 51
    ActiveDocument.Shapes.AddShape(msoShapeRectangle, 0#, 812.4, 623.3, _
        92.45).Select
    ActiveWindow.ActivePane.VerticalPercentScrolled = 0
End Sub

我尝试运行 For Each,如下所示:

Dim pages As Page

For Each pages in ActiveDocument
    'here I have pasted the contents of macro1 except the first and last line' 
Next Page

我的目标是为文档的每一页重复录制的宏。 我请你帮忙创建这个宏,因为它可以节省我一生的时间,谢谢。

谢谢大家

PS:我不是以英语为母语的,如果有不懂的可以问我

【问题讨论】:

    标签: vba ms-word


    【解决方案1】:

    为什么不使用页眉和页脚?在插入菜单上单击页眉、页脚。 然后在页眉和页脚中插入一个矩形。这些矩形将出现在每一页上。

    下面的代码也可以。将光标放在第一页并执行。

    到达。

    Dim a
    a = ActiveDocument.BuiltInDocumentProperties("Number of Pages")
    
    For i = 1 To a
    ActiveDocument.Shapes.AddShape(msoShapeRectangle, 0#, -23.65, 634.05, _
        45.15).Select
    Selection.ShapeRange.ScaleHeight 1.14, msoFalse, msoScaleFromTopLeft
    ActiveWindow.ActivePane.VerticalPercentScrolled = 51
    ActiveDocument.Shapes.AddShape(msoShapeRectangle, 0#, 812.4, 623.3, _
        92.45).Select
    ActiveWindow.ActivePane.VerticalPercentScrolled = 0
    Selection.GoToNext what:=wdGoToPage
    Next
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-11-29
      • 1970-01-01
      • 1970-01-01
      • 2020-10-15
      • 1970-01-01
      • 2016-02-05
      • 2013-05-09
      相关资源
      最近更新 更多