简体   繁体   English

如何在Word文档中使用VBA宏更改不包括标题,子标题,目录,标题的字体大小

[英]How to change font size excluding headings,sub headings, TOC ,Title using VBA macro in word document

My scenario is that I want to change font size of content body excluding title,headings,sub headings,TOC using VBA macro ,simply means change the font actual content body using macro ( Normal style applied to actual content) 我的情况是我想使用VBA宏更改内容主体的字体大小(不包括标题,标题,子标题,目录),仅意味着使用宏更改字体实际内容主体(将标准样式应用于实际内容)

Here is my VBA code: 这是我的VBA代码:

Private Sub Document_Open()
   With ActiveDocument.Content.Find
        .ClearFormatting
        .Replacement.ClearFormatting
        .Forward = True
        .Wrap = wdFindContinue
        .Format = True
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
        .Text = ""
        .Replacement.Text = ""
        .Execute Replace:=wdReplaceAll
        .ClearFormatting
        .Replacement.ClearFormatting
        .Font.Name = "Arial"
        .Replacement.Font.Name = "Calibri"
        .Execute Replace:=wdReplaceAll         
         .ClearFormatting
        .Replacement.ClearFormatting
        .Font.Name = "Times New Roman"
        .Replacement.Font.Name = "Calibri"
        .Execute Replace:=wdReplaceAll      
        .ClearFormatting
        .Replacement.ClearFormatting
        .Font.Size = 11
        .Replacement.Font.Size = 10
        .Execute Replace:=wdReplaceAll                
    End With
End Sub

using this code the whole document font size is changing but font name changing only actual content only using above macro. 使用此代码,整个文档的字体大小正在更改,但是仅使用上述宏,字体名称仅更改实际内容。

Is it possible using VBA macro o change actual contents of document? 是否可以使用VBA宏来更改文档的实际内容?

Can you suggest me how can I do it using VBA Macro? 您能建议我如何使用VBA宏吗?

If you are sure that the style Normal is applied to the document and you want to change the font properties of those parts with Normal style, then you can specify the style in Find as below: 如果您确定将Normal样式应用于文档,并且希望使用Normal样式更改这些部件的字体属性,则可以在“ Find ”中指定样式,如下所示:

ActiveDocument.Content.Find.Style = ActiveDocument.Styles("Normal") . ActiveDocument.Content.Find.Style = ActiveDocument.Styles("Normal")

Also .Replacement.Text = "" will remove all the matching text from your document. 另外, .Replacement.Text = ""将从文档中删除所有匹配的文本。 Make sure that you use .Replacement.Text = "^&" . 确保使用.Replacement.Text = "^&" ^& will replace the same text as found. ^&将替换找到的相同文本。

Sub FormatNormal()
    With ActiveDocument.Content.Find
        .ClearFormatting
        .Style = ActiveDocument.Styles("Normal")
        .Text = ""
        .Replacement.Text = "^&"
        .Replacement.Font.Size = 10
        .Replacement.Font.Name = "Calibri"
        .Replacement.ClearFormatting
        .Forward = True
        .Wrap = wdFindContinue
        .Format = True
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
        .Execute Replace:=wdReplaceAll
    End With
End Sub

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM