我想寫一些excel vba來更改Word文檔中頁眉/頁腳的位置。我想使用VBA更改的項目是「頂部標題」。Excel VBA指定word文檔標題位置
我找不到任何解決方案 - 即使當我錄製單詞宏並更改位置時,宏也是空白的。
任何想法?
我想寫一些excel vba來更改Word文檔中頁眉/頁腳的位置。我想使用VBA更改的項目是「頂部標題」。Excel VBA指定word文檔標題位置
我找不到任何解決方案 - 即使當我錄製單詞宏並更改位置時,宏也是空白的。
任何想法?
我找不到任何解決方案 - 即使當我錄製單詞宏並更改位置時,宏也是空白的。
我可以很容易地在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()
你說的'一個字document'頁眉/頁腳位置的意思。你的意思是頂部標題的內容? –
我的意思是標題本身的位置。在Word中,您可以指定「頂部標題」和「底部頁腳」,默認爲1.25釐米。所以標題距離頁面頂部1.25cm(不同於頁邊距)。我可以用vba修改margin,但不能改變header的位置。 – Kyo