您现在的位置是:首页 > 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分列技巧的应用4
相关文章
文章评论
- 这篇文章还没有收到评论,赶紧来抢沙发吧~