免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 3114 | 回复: 2
打印 上一主题 下一主题

EXCEL 文档格式化 VBA 程序 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-09-05 12:14 |只看该作者 |倒序浏览
我们有些文档是用 EXCEL 写的,很多个 sheet,有的格式比较乱,不方便打印,我录制了一个宏,统一格式化一下,以下是宏的VBA程序,可以根据需要再修改:

  1. Sub 宏1()
  2. '
  3. ' 宏1 Macro
  4. ' AAA 记录的宏
  5. ' 快捷键: Ctrl+Shift+O
  6. '
  7.     ActiveCell.SpecialCells(xlLastCell).Select
  8.     Range("A1").Select
  9.     Cells.Select
  10.     With Selection.Font
  11.         .Name = "宋体"
  12.         .Size = 9
  13.         .Strikethrough = False
  14.         .Superscript = False
  15.         .Subscript = False
  16.         .OutlineFont = False
  17.         .Shadow = False
  18.         .Underline = xlUnderlineStyleNone
  19.     End With
  20.     Selection.Columns.AutoFit
  21.     Selection.Rows.AutoFit
  22.     With ActiveSheet.PageSetup
  23.         .PrintTitleRows = ""
  24.         .PrintTitleColumns = ""
  25.     End With
  26.     ActiveSheet.PageSetup.PrintArea = ""
  27.     With ActiveSheet.PageSetup
  28.         .LeftHeader = ""
  29.         .CenterHeader = "&A"
  30.         .RightHeader = ""
  31.         .LeftFooter = ""
  32.         .CenterFooter = "第 &P 页,共 &N 页"
  33.         .RightFooter = ""
  34.         .LeftMargin = Application.InchesToPoints(0.393700787401575)
  35.         .RightMargin = Application.InchesToPoints(0.393700787401575)
  36.         .TopMargin = Application.InchesToPoints(0.47244094488189)
  37.         .BottomMargin = Application.InchesToPoints(0.47244094488189)
  38.         .HeaderMargin = Application.InchesToPoints(0.236220472440945)
  39.         .FooterMargin = Application.InchesToPoints(0.236220472440945)
  40.         .PrintHeadings = False
  41.         .PrintGridlines = True
  42.         .PrintComments = xlPrintSheetEnd
  43.         .PrintQuality = 600
  44.         .CenterHorizontally = False
  45.         .CenterVertically = False
  46.         .Orientation = xlLandscape
  47.         .Draft = False
  48.         .PaperSize = xlPaperA4
  49.         .FirstPageNumber = xlAutomatic
  50.         .Order = xlDownThenOver
  51.         .BlackAndWhite = False
  52.         .Zoom = 100
  53.     End With
  54.     ActiveWindow.SelectedSheets.PrintPreview
  55.     Range("A1").Select
  56. End Sub
复制代码

论坛徽章:
0
2 [报告]
发表于 2008-09-05 12:16 |只看该作者
在 EXCEL 文件中使用宏有一个问题,容易被某些杀毒软件当作病毒。
可以考虑把 VBA 代码改写到 VFP 程序中,写一个通用工具。

论坛徽章:
0
3 [报告]
发表于 2008-09-05 12:30 |只看该作者
收藏了 tks
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP