0
votes

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)

Here is my VBA code:

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?

Can you suggest me how can I do it using VBA Macro?

1
...and please show what you have up to now adding your code to your question...Kazimierz Jawor

1 Answers

0
votes

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:

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

Also .Replacement.Text = "" will remove all the matching text from your document. Make sure that you use .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