ExcelHome技术论坛

 找回密码
 免费注册

QQ登录

只需一步,快速开始

快捷登录

搜索
EH技术汇-专业的职场技能充电站 妙哉!函数段子手趣味讲函数 Excel服务器-会Excel,做管理系统 Excel Home精品图文教程库
HR薪酬管理数字化实战 Excel 2021函数公式学习大典 Excel数据透视表实战秘技 打造核心竞争力的职场宝典
300集Office 2010微视频教程 数据工作者的案头书 免费直播课集锦 ExcelHome出品 - VBA代码宝免费下载
用ChatGPT与VBA一键搞定Excel WPS表格从入门到精通 Excel VBA经典代码实践指南
123
返回列表 发新帖
楼主: ke3088

[求助] 查找特定格式段落的VBA

[复制链接]

TA的精华主题

TA的得分主题

发表于 2018-3-18 15:51 | 显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件       ★免费下载 ★       ★ 使用帮助

师傅好!
啊、是这样呀!谢谢师傅的详释!

TA的精华主题

TA的得分主题

发表于 2018-3-18 15:52 | 显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件       ★免费下载 ★       ★ 使用帮助

杜前辈好!
OK了!谢谢!

TA的精华主题

TA的得分主题

发表于 2018-3-24 20:14 | 显示全部楼层

杜先生,如果要设置字体段落的上一段是表格就不完美了

TA的精华主题

TA的得分主题

发表于 2018-3-25 02:10 | 显示全部楼层
* 以下不太完美的《自动排版》代码仅供楼主参考:(提请特别注意《标题2345》自动设置宏,即Title2345)
  1. Sub 公文()
  2.     Dim doc As Document, t As Table, j As Long, k As Long
  3.     Set doc = ActiveDocument
  4.     ActiveWindow.View.Type = wdPrintView
  5.     ActiveWindow.ActivePane.View.Zoom.PageFit = wdPageFitBestFit
  6.     With doc
  7.         With .Content.Find
  8.             .Execute "^13", , , 0, , , , , , "^p", 2
  9.             .Execute "^11", , , 0, , , , , , "^p", 2
  10.             .Parent.ListFormat.ConvertNumbersToText
  11.         End With
  12.         If .Tables.Count = 0 Then
  13.             .Select
  14.             正文样式
  15.         Else
  16.             For Each t In .Tables
  17.                 With t.Range
  18.                     .Rows.WrapAroundText = False
  19.                     .Rows.Alignment = wdAlignRowCenter
  20.                     .Font.Name = "仿宋_GB2312"
  21.                     .Font.Name = "Times New Roman"
  22.                     .Font.Color = wdColorDarkRed
  23.                 End With
  24.             Next
  25.             If .Paragraphs(1).Range.Information(wdWithInTable) = False Then
  26.                 .Tables(1).Range.Previous.Select
  27.                 Selection.HomeKey unit:=wdStory, Extend:=wdExtend
  28.                 Selection.MoveEnd unit:=wdCharacter, Count:=1
  29.                 正文样式
  30.             End If
  31.             k = .Tables.Count
  32.             For j = 1 To k
  33.                 If j = k Then Exit For
  34.                 .Range(Start:=.Tables(j).Range.End, End:=.Tables(j + 1).Range.Start).Select
  35.                 正文样式
  36.             Next j
  37.             .Tables(k).Range.Next.Select
  38.             Selection.EndKey unit:=wdStory, Extend:=wdExtend
  39.             正文样式
  40.         End If
  41.     End With

  42.     Title2345

  43.     Auto1

  44.     Selection.HomeKey unit:=wdStory
  45. End Sub
  46. Sub 正文样式()
  47.     Dim i As Paragraph, r As Range
  48.     With Selection
  49.         .ClearFormatting
  50.         CommandBars.FindControl(ID:=122).Execute
  51.         CommandBars.FindControl(ID:=123).Execute
  52.         With .Font
  53.             .Name = "仿宋_GB2312"
  54.             .Name = "Times New Roman"
  55.             .Size = 16
  56.             .Color = wdColorBlue
  57.             .Kerning = 0
  58.             .DisableCharacterSpaceGrid = True
  59.         End With
  60.         With .ParagraphFormat
  61.             .LineSpacing = LinesToPoints(1.25)
  62.             .CharacterUnitFirstLineIndent = 2
  63.             .AutoAdjustRightIndent = False
  64.             .DisableLineHeightGrid = True
  65.         End With
  66.         Set r = .Range
  67.         For Each i In r.Paragraphs
  68.             If Len(i.Range) = 1 And Asc(i.Range) = 13 Then i.Range.Delete
  69.         Next
  70.     End With
  71. End Sub
  72. Sub Auto1()
  73.     With ActiveDocument.Paragraphs(1).Range
  74.         .InsertParagraphAfter
  75.         .InsertParagraphBefore
  76.         .Style = wdStyleHeading1
  77.         With .ParagraphFormat
  78.             .SpaceBeforeAuto = False
  79.             .SpaceAfterAuto = False
  80.             .SpaceBefore = 0
  81.             .SpaceAfter = 0
  82.             .LineSpacing = LinesToPoints(1.15)
  83.             .Alignment = wdAlignParagraphCenter
  84.             .AutoAdjustRightIndent = False
  85.             .DisableLineHeightGrid = True
  86.         End With
  87.         .Paragraphs(1).Range.Font.Size = 21
  88.         .Paragraphs(3).Range.Font.Size = 26
  89.     End With
  90. End Sub
  91. Sub Title2345()
  92.     Dim mt, reg As Object, n&, m&, L&, ostr$, sr$, r1$, r2$, r3$, r4$
  93.     ostr = Replace(ActiveDocument.Content, Chr(7), "")
  94.     sr = "一二三四五六七八九十百零千〇"
  95.     r1 = "^[" & sr & "]+、"
  96.     r2 = "^[((]\s*[" & sr & "]+\s*[))]"
  97.     r3 = "^\d+[、..]"
  98.     r4 = "^[((]\s*\d+\s*[))]"
  99.     Set reg = CreateObject("vbscript.regexp")
  100.     With reg
  101.         .Global = True
  102.         .MultiLine = True
  103.         .Pattern = "" & r2 & "|" & r1 & "|" & r4 & "|" & r3 & ""
  104.         For Each mt In .Execute(ostr)
  105.             m = mt.FirstIndex
  106.             n = mt.Length
  107.             With ActiveDocument.Range(m, m + n)
  108.                 If Not .Information(wdWithInTable) Then
  109.                     .Expand 4
  110.                     L = Len(.Text)
  111.                     .Collapse
  112.                     If .MoveWhile(sr, L) > 0 Then
  113.                         .Expand 4
  114.                         .Style = "标题 2"
  115.                         .Font.ColorIndex = 6
  116.                     ElseIf .MoveWhile("((", L) > 0 Then
  117.                         If .MoveWhile(sr, L) > 0 Then
  118.                             .Expand 4
  119.                             .Style = "标题 3"
  120.                             With .Font
  121.                                 .Name = "楷体_GB2312"
  122.                                 .Name = "Times New Roman"
  123.                                 .ColorIndex = 5
  124.                             End With
  125.                         Else
  126.                             .Expand 4
  127.                             .Style = "标题 5"
  128.                             With .Font
  129.                                 .Name = "仿宋_GB2312"
  130.                                 .Name = "Times New Roman"
  131.                                 .ColorIndex = 12
  132.                             End With
  133.                         End If
  134.                     Else
  135.                         .Expand 4
  136.                         .Style = "标题 4"
  137.                         With .Font
  138.                             .Name = "仿宋_GB2312"
  139.                             .Name = "Times New Roman"
  140.                             .ColorIndex = 11
  141.                         End With
  142.                     End If
  143.                     If .Sentences.Count = 1 Then
  144. '                        If v Like "*[。:;,、!?…—.:;,!?]?" Then .Characters.Last.Previous.Delete
  145.                     Else
  146.                         With .Font
  147.                             .Name = "仿宋_GB2312"
  148.                             .Name = "Times New Roman"
  149.                             .Bold = False
  150.                             .Color = wdColorBlue
  151.                         End With
  152.                         With .Sentences(1).Font
  153.                             .Bold = True
  154.                             .Color = wdColorBrown
  155.                         End With
  156.                     End If
  157.                     With .Font
  158.                         .Size = 16
  159.                         .Kerning = 0
  160.                         .DisableCharacterSpaceGrid = True
  161.                     End With
  162.                     With .ParagraphFormat
  163.                         .SpaceBeforeAuto = False
  164.                         .SpaceAfterAuto = False
  165.                         .SpaceBefore = 0
  166.                         .SpaceAfter = 0
  167.                         .LineSpacing = LinesToPoints(1.25)
  168.                         .CharacterUnitFirstLineIndent = 2
  169.                         .AutoAdjustRightIndent = False
  170.                         .DisableLineHeightGrid = True
  171.                         .KeepWithNext = False
  172.                         .KeepTogether = False
  173.                     End With
  174.                 End If
  175.             End With
  176.         Next
  177.     End With
  178. End Sub
复制代码

TA的精华主题

TA的得分主题

 楼主| 发表于 2018-3-25 11:10 | 显示全部楼层
413191246se 发表于 2018-3-25 02:10
* 以下不太完美的《自动排版》代码仅供楼主参考:(提请特别注意《标题2345》自动设置宏,即Title2345)

好的,谢谢!413191246se老师
您需要登录后才可以回帖 登录 | 免费注册

本版积分规则

关闭

最新热点上一条 /1 下一条

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

GMT+8, 2024-4-26 20:40 , Processed in 0.034001 second(s), 7 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 1999-2023 Wooffice Inc.

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

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

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