Excel精英培训网

 找回密码
 注册
数据透视表40+个常用小技巧,让你一次学会!
查看: 5086|回复: 10

[已解决]求页面设置代码

[复制链接]
发表于 2014-5-19 08:31 | 显示全部楼层 |阅读模式
本帖最后由 dyzx 于 2014-5-19 14:38 编辑

麻烦各位老师帮忙写一段代码(将表1格式设置成表2格式,A4纸输出)
最佳答案
2014-5-19 09:51
本帖最后由 zjdh 于 2014-5-19 10:16 编辑
  1. Sub test()
  2.     For Each SH In Sheets
  3.         With SH
  4.             .Rows(1).RowHeight = 30
  5.             .Rows(2).RowHeight = 30
  6.             .Rows("4:12").RowHeight = 40
  7.             For I = 1 To 16 Step 2
  8.                 With .Range(.Cells(4, I), .Cells(12, I + 1))
  9.                     .Borders.LineStyle = xlDouble
  10.                     .Borders(xlInsideVertical).LineStyle = xlDash
  11.                     .Borders(xlInsideHorizontal).LineStyle = xlContinuous
  12.                     .Borders(xlInsideHorizontal).Weight = xlThin
  13.                     .VerticalAlignment = xlCenter
  14.                 End With
  15.                 .Columns(I).ColumnWidth = 6
  16.                 .Columns(I + 1).ColumnWidth = 2.5
  17.             Next
  18.             .Rows("1:2").Font.Size = 20
  19.             .Range("F2:J2").Merge
  20.             With .Range("G16:I16")
  21.                 .Merge
  22.                 .RowHeight = 30
  23.                 .Borders.LineStyle = xlDouble
  24.                 .Value = "讲    桌"
  25.                 .Font.Size = 20
  26.             End With
  27.            .Cells.HorizontalAlignment = xlCenter
  28.         .Cells.VerticalAlignment = xlCenter
  29.         End With
  30.     Next
  31. End Sub
复制代码

页面设置.rar

9.28 KB, 下载次数: 14

发表于 2014-5-19 08:48 | 显示全部楼层
回复

使用道具 举报

 楼主| 发表于 2014-5-19 09:07 | 显示全部楼层
zjdh 发表于 2014-5-19 08:48
录制一个宏就都有啦!

录制的宏太长了,能否写个简单点的。
回复

使用道具 举报

发表于 2014-5-19 09:10 | 显示全部楼层
直接用格式刷呢。
回复

使用道具 举报

 楼主| 发表于 2014-5-19 09:14 | 显示全部楼层
hwc2ycy 发表于 2014-5-19 09:10
直接用格式刷呢。

用格式刷怎样刷,如果有多个表1的表,现要统一设置成表2的格式,应该怎样设置?多谢指教。
回复

使用道具 举报

发表于 2014-5-19 09:51 | 显示全部楼层    本楼为最佳答案   
本帖最后由 zjdh 于 2014-5-19 10:16 编辑
  1. Sub test()
  2.     For Each SH In Sheets
  3.         With SH
  4.             .Rows(1).RowHeight = 30
  5.             .Rows(2).RowHeight = 30
  6.             .Rows("4:12").RowHeight = 40
  7.             For I = 1 To 16 Step 2
  8.                 With .Range(.Cells(4, I), .Cells(12, I + 1))
  9.                     .Borders.LineStyle = xlDouble
  10.                     .Borders(xlInsideVertical).LineStyle = xlDash
  11.                     .Borders(xlInsideHorizontal).LineStyle = xlContinuous
  12.                     .Borders(xlInsideHorizontal).Weight = xlThin
  13.                     .VerticalAlignment = xlCenter
  14.                 End With
  15.                 .Columns(I).ColumnWidth = 6
  16.                 .Columns(I + 1).ColumnWidth = 2.5
  17.             Next
  18.             .Rows("1:2").Font.Size = 20
  19.             .Range("F2:J2").Merge
  20.             With .Range("G16:I16")
  21.                 .Merge
  22.                 .RowHeight = 30
  23.                 .Borders.LineStyle = xlDouble
  24.                 .Value = "讲    桌"
  25.                 .Font.Size = 20
  26.             End With
  27.            .Cells.HorizontalAlignment = xlCenter
  28.         .Cells.VerticalAlignment = xlCenter
  29.         End With
  30.     Next
  31. End Sub
复制代码

点评

赞一个。  发表于 2014-5-19 09:52

评分

参与人数 1 +1 收起 理由
dyzx + 1 很给力!

查看全部评分

回复

使用道具 举报

 楼主| 发表于 2014-5-20 08:41 | 显示全部楼层
zjdh 发表于 2014-5-19 09:51

zjdh老师:如果要4纸输出,页边距上下为2.5cn、左右为1.5cn,哪代码应该怎样?多谢。
回复

使用道具 举报

发表于 2014-5-20 09:44 | 显示全部楼层
Sub Macro1()
    With ActiveSheet.PageSetup
        .TopMargin = Application.InchesToPoints(0.98)
        .BottomMargin = Application.InchesToPoints(0.59)
        .PaperSize = xlPaperA4
    End With
End Sub
回复

使用道具 举报

 楼主| 发表于 2014-5-20 10:07 | 显示全部楼层
zjdh 发表于 2014-5-20 09:44
Sub Macro1()
    With ActiveSheet.PageSetup
        .TopMargin = Application.InchesToPoints(0.98)
...

zjdh老师:上、下边距各为2.5cn,左、右边距各为1.5cn,且整个表格居中,多谢,辛苦了。
回复

使用道具 举报

发表于 2014-5-20 10:16 | 显示全部楼层
本帖最后由 zjdh 于 2014-5-20 10:19 编辑

没看清
Sub Macro1()
    With ActiveSheet.PageSetup
        .TopMargin = Application.InchesToPoints(0.98)
        .BottomMargin = Application.InchesToPoints(0.98)
        .LeftMargin = Application.InchesToPoints(0.59)
        .RightMargin = Application.InchesToPoints(0.59)
        .CenterHorizontally = True
        .CenterVertically = True
        .PaperSize = xlPaperA4
    End With
End Sub

评分

参与人数 1 +2 收起 理由
dyzx + 2 很给力!

查看全部评分

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|Excel精英培训 ( 豫ICP备11015029号 )

GMT+8, 2024-4-26 07:32 , Processed in 0.634596 second(s), 15 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表