Excel VBA指定word文档标题位置

时间:2014-04-02 13:00:58

标签: vba excel-vba ms-word excel

我试图编写一些excel vba来更改word文档中页眉/页脚的位置。我想要使​​用VBA更改的项目是"来自Top"的标题。

我找不到任何解决方案 - 即使我录制一个单词宏并改变位置,那么宏也是空白的。

有什么想法吗?

1 个答案:

答案 0 :(得分:0)

  

我找不到任何解决方案 - 即使我录制一个单词宏并改变位置,那么宏也是空白的。

我可以在VBA Word中轻松录制宏。这就是我得到的

Sub Macro2()
'
' Macro2 Macro
'
'
    If ActiveWindow.View.SplitSpecial <> wdPaneNone Then
        ActiveWindow.Panes(2).Close
    End If
    If ActiveWindow.ActivePane.View.Type = wdNormalView Or ActiveWindow. _
        ActivePane.View.Type = wdOutlineView Then
        ActiveWindow.ActivePane.View.Type = wdPrintView
    End If
    ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
    With Selection.PageSetup
        .LineNumbering.Active = False
        .Orientation = wdOrientPortrait
        .TopMargin = InchesToPoints(1)
        .BottomMargin = InchesToPoints(1)
        .LeftMargin = InchesToPoints(1)
        .RightMargin = InchesToPoints(1)
        .Gutter = InchesToPoints(0)
        .HeaderDistance = InchesToPoints(0.7)
        .FooterDistance = InchesToPoints(0.5)
        .PageWidth = InchesToPoints(8.5)
        .PageHeight = InchesToPoints(11)
        .FirstPageTray = wdPrinterDefaultBin
        .OtherPagesTray = wdPrinterDefaultBin
        .SectionStart = wdSectionNewPage
        .OddAndEvenPagesHeaderFooter = False
        .DifferentFirstPageHeaderFooter = False
        .VerticalAlignment = wdAlignVerticalTop
        .SuppressEndnotes = False
        .MirrorMargins = False
        .TwoPagesOnOne = False
        .BookFoldPrinting = False
        .BookFoldRevPrinting = False
        .BookFoldPrintingSheets = 1
        .GutterPos = wdGutterPosLeft
    End With
    ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
End Sub

您真正想要的是.HeaderDistance = InchesToPoints()