网站首页 美食营养 游戏数码 手工爱好 生活家居 健康养生 运动户外 职场理财 情感交际 母婴教育 生活知识 知识问答

Excel VBA 页面设置

时间:2026-02-13 06:07:58

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

Excel VBA 页面设置

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

Excel VBA 页面设置

Excel VBA 页面设置

3、在模块中编写如下代码:

Sub 初始化设置()

    Cells.Select

    Selection.RowHeight = 16   

    Selection.ColumnWidth = 9

    

     With ActiveSheet.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 = 100

       End With

End Sub

这部分代码单位英寸。

Excel VBA 页面设置

4、如果我们想直接设置厘米单位,我们这一将代码改为如下:

Sub 初始化设置()

    ActiveSheet.Cells.RowHeight = 16

    ActiveSheet.Cells.ColumnWidth = 9

  With ActiveSheet.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 = 100

    End With

End Sub

Excel VBA 页面设置

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

Excel VBA 页面设置

© 2026 一点资料
信息来自网络 所有数据仅供参考
有疑问请联系站长 site.kefu@gmail.com