簡體   English   中英

MS word macro vba For Each page

[英]MS word macro vba For Each page

我的問題是我必須在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:如果你不明白的話,我不是英語母語人士

為什么不使用頁眉和頁腳? 在“插入”菜單上,單擊“頁眉”,“頁腳”。 然后在頁眉和頁腳中插入一個矩形。 這些矩形將出現在每個頁面上。

以下代碼也可以使用。 將光標放在第一頁上並執行。

Arrivederci。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM