您现在的位置是:首页 > Excel技巧>Excel VBA自动设置页边距、页眉页脚

excel页眉页脚怎么设置边距-Excel VBA自动设置页边距、页眉页脚

发布于2022-04-150人已围观

用VBA给当前Excel表自动设置页边距和页眉页脚。

通过代码自动控制报表的位置,同时自动添加工作表名作为报表页眉,加页数作为页脚。


详细代码:

Sub Excel设置页眉页脚()

'

    With ActiveSheet.PageSetup

        .LeftMargin = Application.InchesToPoints(0.7)

        .RightMargin = Application.InchesToPoints(0.6)

        .TopMargin = Application.InchesToPoints(0.5)

        .BottomMargin = Application.InchesToPoints(0.4)

        .HeaderMargin = Application.InchesToPoints(0.2)

        .FooterMargin = Application.InchesToPoints(0.2)

        .Zoom = False

        .FitToPagesWide = 1

        .FitToPagesTall = 1

    End With

    With ActiveSheet.PageSetup

        .LeftHeader = ""

        .CenterHeader = "&A"

        .RightHeader = ""

        .LeftFooter = ""

        .CenterFooter = ""

        .RightFooter = "&P/&N"

    End With

    ActiveWindow.SelectedSheets.PrintPreview

End Sub


效果图:

excel页眉页脚怎么设置边距


相关文章

文章评论

表情

共0条评论
  • 这篇文章还没有收到评论,赶紧来抢沙发吧~

标签云

站长特荐