ExcelHome技术论坛

 找回密码
 免费注册

QQ登录

只需一步,快速开始

快捷登录

搜索
EH技术汇-专业的职场技能充电站 妙哉!函数段子手趣味讲函数 Excel服务器-会Excel,做管理系统 效率神器,一键搞定繁琐工作
HR薪酬管理数字化实战 Excel 2021函数公式学习大典 Excel数据透视表实战秘技 打造核心竞争力的职场宝典
让更多数据处理,一键完成 数据工作者的案头书 免费直播课集锦 ExcelHome出品 - VBA代码宝免费下载
用ChatGPT与VBA一键搞定Excel WPS表格从入门到精通 Excel VBA经典代码实践指南
查看: 475|回复: 5

[求助] 经常排一些固定格式文件,能给写个VBA刷出格式来,自己再改一下细节

[复制链接]

TA的精华主题

TA的得分主题

发表于 2023-3-6 17:03 | 显示全部楼层 |阅读模式
经常排相似格式的文件,不会VBA,只是设置快捷键 ,效率有点太低,请论坛里的高手帮写个VBA,提高些工作效率。

附件里是经常出现的两种情况,黑色字体的是一种,红色的是一种,但要求是一样的。
只要是能刷出要求的格式就行,自动目录能生成三级目录就可以。
小弟在这里提前感谢热心的坛友。

这是排版的要求

这是排版的要求

文件排版内容.rar

18.15 KB, 下载次数: 9

TA的精华主题

TA的得分主题

 楼主| 发表于 2023-3-6 17:16 | 显示全部楼层
小白一枚,又不会英文,请高手帮写一下代码,在此感谢

TA的精华主题

TA的得分主题

发表于 2023-3-7 11:04 | 显示全部楼层
其实,录制宏就可以了
  1. Sub 自动排版()
  2.     With ActiveDocument.Styles("标题 1").Font
  3.         .NameFarEast = "黑体"
  4.         .NameAscii = "Times New Roman"
  5.         .NameOther = "Times New Roman"
  6.         .Name = "Times New Roman"
  7.         .Size = 22
  8.         .Bold = True
  9.         .Color = wdColorAutomatic
  10.         .Engrave = False
  11.         .Superscript = False
  12.         .Subscript = False
  13.         .Scaling = 100
  14.         .Kerning = 二号
  15.     End With
  16.     With ActiveDocument.Styles("标题 1").ParagraphFormat
  17.         .LeftIndent = CentimetersToPoints(0)
  18.         .RightIndent = CentimetersToPoints(0)
  19.         .SpaceBefore = 5
  20.         .SpaceBeforeAuto = False
  21.         .SpaceAfter = 5
  22.         .SpaceAfterAuto = False
  23.         .LineSpacingRule = wdLineSpaceExactly
  24.         .LineSpacing = 26
  25.         .Alignment = wdAlignParagraphCenter
  26.         .WidowControl = False
  27.         .KeepWithNext = True
  28.         .KeepTogether = True
  29.         .PageBreakBefore = False
  30.         .NoLineNumber = False
  31.         .Hyphenation = True
  32.         .FirstLineIndent = CentimetersToPoints(0)
  33.         .OutlineLevel = wdOutlineLevel1
  34.         .CharacterUnitLeftIndent = 0
  35.         .CharacterUnitRightIndent = 0
  36.         .CharacterUnitFirstLineIndent = 0
  37.         .LineUnitBefore = 1
  38.         .LineUnitAfter = 1
  39.         .MirrorIndents = False
  40.         .TextboxTightWrap = wdTightNone
  41.         .AutoAdjustRightIndent = False
  42.         .DisableLineHeightGrid = True
  43.         .FarEastLineBreakControl = True
  44.         .WordWrap = True
  45.         .HangingPunctuation = True
  46.         .HalfWidthPunctuationOnTopOfLine = False
  47.         .AddSpaceBetweenFarEastAndAlpha = True
  48.         .AddSpaceBetweenFarEastAndDigit = True
  49.         .BaseLineAlignment = wdBaselineAlignAuto
  50.     End With
  51.     ActiveDocument.Styles("标题 1").NoSpaceBetweenParagraphsOfSameStyle = False
  52.     With ActiveDocument.Styles("标题 1")
  53.         .AutomaticallyUpdate = False
  54.         .BaseStyle = "正文"
  55.         .NextParagraphStyle = "正文"
  56.     End With
  57.     With ActiveDocument.Styles("标题 2").Font
  58.         .NameFarEast = "黑体"
  59.         .NameAscii = "Times New Roman"
  60.         .NameOther = "Times New Roman"
  61.         .Name = "Times New Roman"
  62.         .Size = 16
  63.         .Bold = False
  64.         .Italic = False
  65.         .Underline = wdUnderlineNone
  66.         .UnderlineColor = wdColorAutomatic
  67.         .StrikeThrough = False
  68.         .DoubleStrikeThrough = False
  69.         .Outline = False
  70.         .Emboss = False
  71.         .Shadow = False
  72.         .Hidden = False
  73.         .SmallCaps = False
  74.         .AllCaps = False
  75.         .Color = wdColorAutomatic
  76.         .Engrave = False
  77.         .Superscript = False
  78.         .Subscript = False
  79.         .Scaling = 100
  80.         .Kerning = 1
  81.         .Animation = wdAnimationNone
  82.         .DisableCharacterSpaceGrid = False
  83.         .EmphasisMark = wdEmphasisMarkNone
  84.     End With
  85.     With ActiveDocument.Styles("标题 2").ParagraphFormat
  86.         .LeftIndent = CentimetersToPoints(0)
  87.         .RightIndent = CentimetersToPoints(0)
  88.         .SpaceBefore = 5
  89.         .SpaceBeforeAuto = False
  90.         .SpaceAfter = 5
  91.         .SpaceAfterAuto = False
  92.         .LineSpacingRule = wdLineSpaceExactly
  93.         .LineSpacing = 26
  94.         .Alignment = wdAlignParagraphJustify
  95.         .WidowControl = False
  96.         .KeepWithNext = True
  97.         .KeepTogether = True
  98.         .PageBreakBefore = False
  99.         .NoLineNumber = False
  100.         .Hyphenation = True
  101.         .FirstLineIndent = CentimetersToPoints(0)
  102.         .OutlineLevel = wdOutlineLevel2
  103.         .CharacterUnitLeftIndent = 0
  104.         .CharacterUnitRightIndent = 0
  105.         .CharacterUnitFirstLineIndent = 0
  106.         .LineUnitBefore = 1
  107.         .LineUnitAfter = 1
  108.         .MirrorIndents = False
  109.         .TextboxTightWrap = wdTightNone
  110.         .AutoAdjustRightIndent = False
  111.         .DisableLineHeightGrid = True
  112.         .FarEastLineBreakControl = True
  113.         .WordWrap = True
  114.         .HangingPunctuation = True
  115.         .HalfWidthPunctuationOnTopOfLine = False
  116.         .AddSpaceBetweenFarEastAndAlpha = True
  117.         .AddSpaceBetweenFarEastAndDigit = True
  118.         .BaseLineAlignment = wdBaselineAlignAuto
  119.     End With
  120.     ActiveDocument.Styles("标题 2").NoSpaceBetweenParagraphsOfSameStyle = False
  121.     With ActiveDocument.Styles("标题 2")
  122.         .AutomaticallyUpdate = False
  123.         .BaseStyle = "正文"
  124.         .NextParagraphStyle = "正文"
  125.     End With
  126.     With ActiveDocument.Styles("标题 3").Font
  127.         .NameFarEast = "仿宋_GB2312"
  128.         .NameAscii = "Times New Roman"
  129.         .NameOther = "Times New Roman"
  130.         .Name = "Times New Roman"
  131.         .Size = 16
  132.         .Bold = True
  133.         .Italic = False
  134.         .Underline = wdUnderlineNone
  135.         .UnderlineColor = wdColorAutomatic
  136.         .StrikeThrough = False
  137.         .DoubleStrikeThrough = False
  138.         .Outline = False
  139.         .Emboss = False
  140.         .Shadow = False
  141.         .Hidden = False
  142.         .SmallCaps = False
  143.         .AllCaps = False
  144.         .Color = wdColorAutomatic
  145.         .Engrave = False
  146.         .Superscript = False
  147.         .Subscript = False
  148.         .Scaling = 100
  149.         .Kerning = 1
  150.         .Animation = wdAnimationNone
  151.         .DisableCharacterSpaceGrid = False
  152.         .EmphasisMark = wdEmphasisMarkNone
  153.     End With
  154.     With ActiveDocument.Styles("标题 3").ParagraphFormat
  155.         .LeftIndent = CentimetersToPoints(0)
  156.         .RightIndent = CentimetersToPoints(0)
  157.         .SpaceBefore = 2.5
  158.         .SpaceBeforeAuto = False
  159.         .SpaceAfter = 2.5
  160.         .SpaceAfterAuto = False
  161.         .LineSpacingRule = wdLineSpaceExactly
  162.         .LineSpacing = 26
  163.         .Alignment = wdAlignParagraphJustify
  164.         .WidowControl = False
  165.         .KeepWithNext = True
  166.         .KeepTogether = True
  167.         .PageBreakBefore = False
  168.         .NoLineNumber = False
  169.         .Hyphenation = True
  170.         .FirstLineIndent = CentimetersToPoints(0.35)
  171.         .OutlineLevel = wdOutlineLevel3
  172.         .CharacterUnitLeftIndent = 0
  173.         .CharacterUnitRightIndent = 0
  174.         .CharacterUnitFirstLineIndent = 2
  175.         .LineUnitBefore = 0.5
  176.         .LineUnitAfter = 0.5
  177.         .MirrorIndents = False
  178.         .TextboxTightWrap = wdTightNone
  179.         .AutoAdjustRightIndent = False
  180.         .DisableLineHeightGrid = True
  181.         .FarEastLineBreakControl = True
  182.         .WordWrap = True
  183.         .HangingPunctuation = True
  184.         .HalfWidthPunctuationOnTopOfLine = False
  185.         .AddSpaceBetweenFarEastAndAlpha = True
  186.         .AddSpaceBetweenFarEastAndDigit = True
  187.         .BaseLineAlignment = wdBaselineAlignAuto
  188.     End With
  189.     ActiveDocument.Styles("标题 3").NoSpaceBetweenParagraphsOfSameStyle = False
  190.     With ActiveDocument.Styles("标题 3")
  191.         .AutomaticallyUpdate = True
  192.         .BaseStyle = "正文"
  193.         .NextParagraphStyle = "正文"
  194.     End With
  195.     With ActiveDocument.Styles("正文").Font
  196.         .NameFarEast = "仿宋_GB2312"
  197.         .NameAscii = "Times New Roman"
  198.         .NameOther = "Times New Roman"
  199.         .Name = "Times New Roman"
  200.         .Size = 16
  201.         .Bold = False
  202.         .Italic = False
  203.         .Underline = wdUnderlineNone
  204.         .UnderlineColor = wdColorAutomatic
  205.         .StrikeThrough = False
  206.         .DoubleStrikeThrough = False
  207.         .Outline = False
  208.         .Emboss = False
  209.         .Shadow = False
  210.         .Hidden = False
  211.         .SmallCaps = False
  212.         .AllCaps = False
  213.         .Color = wdColorAutomatic
  214.         .Engrave = False
  215.         .Superscript = False
  216.         .Subscript = False
  217.         .Scaling = 100
  218.         .Kerning = 1
  219.         .Animation = wdAnimationNone
  220.         .DisableCharacterSpaceGrid = False
  221.         .EmphasisMark = wdEmphasisMarkNone
  222.     End With
  223.     With ActiveDocument.Styles("正文").ParagraphFormat
  224.         .LeftIndent = CentimetersToPoints(0)
  225.         .RightIndent = CentimetersToPoints(0)
  226.         .SpaceBefore = 0
  227.         .SpaceBeforeAuto = False
  228.         .SpaceAfter = 0
  229.         .SpaceAfterAuto = False
  230.         .LineSpacingRule = wdLineSpaceExactly
  231.         .LineSpacing = 26
  232.         .Alignment = wdAlignParagraphJustify
  233.         .WidowControl = False
  234.         .KeepWithNext = False
  235.         .KeepTogether = False
  236.         .PageBreakBefore = False
  237.         .NoLineNumber = False
  238.         .Hyphenation = True
  239.         .FirstLineIndent = CentimetersToPoints(0.35)
  240.         .OutlineLevel = wdOutlineLevelBodyText
  241.         .CharacterUnitLeftIndent = 0
  242.         .CharacterUnitRightIndent = 0
  243.         .CharacterUnitFirstLineIndent = 2
  244.         .LineUnitBefore = 0
  245.         .LineUnitAfter = 0
  246.         .MirrorIndents = False
  247.         .TextboxTightWrap = wdTightNone
  248.         .AutoAdjustRightIndent = False
  249.         .DisableLineHeightGrid = True
  250.         .FarEastLineBreakControl = True
  251.         .WordWrap = True
  252.         .HangingPunctuation = True
  253.         .HalfWidthPunctuationOnTopOfLine = False
  254.         .AddSpaceBetweenFarEastAndAlpha = True
  255.         .AddSpaceBetweenFarEastAndDigit = True
  256.         .BaseLineAlignment = wdBaselineAlignAuto
  257.     End With
  258.     ActiveDocument.Styles("正文").NoSpaceBetweenParagraphsOfSameStyle = False
  259.     With ActiveDocument.Styles("正文")
  260.         .AutomaticallyUpdate = False
  261.         .BaseStyle = ""
  262.         .NextParagraphStyle = "正文文本缩进 2"
  263.     End With
  264. End Sub
复制代码

TA的精华主题

TA的得分主题

发表于 2023-3-7 11:06 | 显示全部楼层
本帖最后由 zldccmx 于 2023-3-7 11:13 编辑

这是录制宏的样例

Test.zip

22.29 KB, 下载次数: 10

TA的精华主题

TA的得分主题

 楼主| 发表于 2023-3-8 09:19 | 显示全部楼层
zldccmx 发表于 2023-3-7 11:06
这是录制宏的样例

不运行呢,我不会英文

TA的精华主题

TA的得分主题

发表于 2023-3-8 09:44 | 显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件       ★免费下载 ★       ★ 使用帮助
zhdqsd 发表于 2023-3-8 09:19
不运行呢,我不会英文

不需要你会英语,但是你应该会一点VBA基础常识。
既然在VBA模块提问。那就应该知道如何切换到代码窗口,然后 再 点 运行 就可以了,或者在这个界面下,按键盘上的F5键。
您需要登录后才可以回帖 登录 | 免费注册

本版积分规则

手机版|关于我们|联系我们|ExcelHome

GMT+8, 2024-11-22 16:40 , Processed in 0.039521 second(s), 8 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 1999-2023 Wooffice Inc.

沪公网安备 31011702000001号 沪ICP备11019229号-2

本论坛言论纯属发表者个人意见,任何违反国家相关法律的言论,本站将协助国家相关部门追究发言者责任!     本站特聘法律顾问:李志群律师

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