Excel VBA 页面设置

 时间:2024-10-18 00:20:04

对于经常做Excel表格的小伙伴们,经常需要设置Excel的打印页面和字体、页眉页脚等,那么如何使用VBA来完成重复的操作呢?我们一起学习一下。

Excel VBA 页面设置

工具/原料

电脑

officeexcel

方法/步骤

1、打开新建一个并打开EXCEL工作表

Excel VBA 页面设置

2、使用Alt+F11组合快捷键进入vbe编辑器或者单击【开发工具】-VIsualBasic,并插入一个新的模块。如图所示。

Excel VBA 页面设置

Excel VBA 页面设置

3、在模块中编写如下代码:Sub初始化设置()Cells.SelectSel娣定撰钠ection.RowHei爿讥旌护ght=16Selection.ColumnWidth=9WithActiveSheet.PageSetup.RightFooter="".LeftMargin=Application.InchesToPoints(0.196850393700787).RightMargin=Application.InchesToPoints(0.196850393700787).TopMargin=Application.InchesToPoints(0.590551181102362).BottomMargin=Application.InchesToPoints(0.393700787401575).HeaderMargin=Application.InchesToPoints(0.196850393700787).FooterMargin=Application.InchesToPoints(0.196850393700787).Zoom=100EndWithEndSub这部分代码单位英寸。

Excel VBA 页面设置

4、如果我们想直接设置厘米单位,我们这一将蜣贺鱿柢代码改为如下:Sub初始化设置()ActiveSheet.Cells.RowHeight=16ActiveSheet缕计瓤账.Cells.ColumnWidth=9WithActiveSheet.PageSetup.LeftMargin=Application.CentimetersToPoints(0.5).RightMargin=Application.CentimetersToPoints(0.5).TopMargin=Application.CentimetersToPoints(1.5).BottomMargin=Application.CentimetersToPoints(1)'底.HeaderMargin=Application.CentimetersToPoints(0.5)'页眉.FooterMargin=Application.CentimetersToPoints(0.5)'页脚.Zoom=100EndWithEndSub

Excel VBA 页面设置

5、其设置的效果为行高16,列宽9,页面设置如下图所示。

Excel VBA 页面设置

Excel中Bin2dec函数怎么用? Excel如何用VB编辑组合框combox的下拉预设值 Excel表格中怎么使用LENB函数算多少个字节? EXCEL自定义函数 Excel中如何快速查出一列数据中的前10项?
热门搜索
樱桃小丸子的图片 黄蜡石图片 聊天图片不用打字搞笑 玻化砖图片 花卉大全图片