人气 4760

Excel VBA自动设置页边距、页眉页脚 [复制链接]

多看少说没错- 2017-4-25 16:36:16
用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.PrintPreviewEnd Sub
效果图:

1493109629124891.jpg

1493109629124891.jpg
您需要登录后才可以回帖 登录 | 立即注册

QQ|手机版|精益人 ( 沪ICP备19004111号-1 )|网站地图

GMT+8, 2024-12-22 18:37 , Processed in 0.247969 second(s), 22 queries .

Powered by Lean.ren X3.5 Licensed  © 2001-2030 LEAN.REN