Excel VBA 页面设置

对于经常做Excel表格的小伙伴们,经常需要设置Excel的打印页面和字体、页眉页脚等,那么若何利用VBA来完当作反复的操作呢?我们一路进修一下。

东西/原料

  • 电脑
  • office excel

方式/步调

  1. 1

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

  2. 2

    利用Alt+F11组合快捷键进入vbe编纂器或者单击【开辟东西】-VIsual Basic,并插入一个新的模块。如图所示。

  3. 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

    这部门代码单元英寸。

  4. 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

  5. 5

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

  • 发表于 2019-09-05 20:01
  • 阅读 ( 823 )
  • 分类:其他类型

你可能感兴趣的文章

相关问题

0 条评论

请先 登录 后评论
联系我们:uytrv@hotmail.com 问答工具