Consulting

Results 1 to 3 of 3

Thread: Changing font name, size, bold, etc...

  1. #1
    VBAX Regular
    Joined
    Jan 2018
    Posts
    58
    Location

    Changing font name, size, bold, etc...

    Hi again,
    I want change font name, size, bold, etc... Code is divided by 2 parts: 1 - changing fontname, 2 - changing size, bold, etc..,
    They work ok separately, but when I connect them in one macro it working only first part. What I'm doing wrong?
    Thanks in advanced.

    Sub Makro_change_font_and_format()
    '
    'changing font
       Dim zRng As Word.Range
      Set zRng = ActiveDocument.Range
      With zRng.Find
        .Text = "Abc"
        With .Replacement
        .Font.Name = "Arial Narrow"
        End With
        
        .Execute Replace:=wdReplaceAll
      End With
    albl_Exit:
    Exit Sub
        
        'changing color, size, etc....
            With Selection.Find.Replacement.Font
            .Size = 9
            .bold = True
            .Color = 1403396
           
        End With
        With Selection.Find.Replacement.ParagraphFormat
            .SpaceBefore = 0
            .SpaceBeforeAuto = False
            .SpaceAfter = 0
            .SpaceAfterAuto = False
            .LineSpacingRule = wdLineSpaceMultiple
            .LineSpacing = LinesToPoints(0.9)
            .Alignment = wdAlignParagraphRight
            .LineUnitBefore = 0
            .LineUnitAfter = 0
        End With
        
        With Selection.Find
            .Text = "Abc"
            .Replacement.Text = ""
            .Forward = True
            .Wrap = wdFindContinue
            .Format = True
            
        End With
        Selection.Find.Execute Replace:=wdReplaceAll
    End Sub

  2. #2
    Use the following instead - but bear in mind that the Paragraph formatting applies to the whole paragraph that the found text resides in.

    Sub Makro_change_font_and_format()
    Dim zRng As Word.Range
        Set zRng = ActiveDocument.Range
        With zRng.Find
            .Text = "Abc"
            With .Replacement
                .ClearFormatting
                .Font.Name = "Arial Narrow"
                .Font.Size = 9
                .Font.Bold = True
                .Font.Color = 1403396
                With .ParagraphFormat 'the whole paragraph
                    .SpaceBefore = 0
                    .SpaceBeforeAuto = False
                    .SpaceAfter = 0
                    .SpaceAfterAuto = False
                    .LineSpacingRule = wdLineSpaceMultiple
                    .LineSpacing = LinesToPoints(0.9)
                    .Alignment = wdAlignParagraphRight
                    .LineUnitBefore = 0
                    .LineUnitAfter = 0
                End With
            End With
            .Execute Replace:=wdReplaceAll
        End With
    lbl_Exit:
        Set zRng = Nothing
        Exit Sub
    End Sub
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

  3. #3
    I found this topic very timely, I was already thinking of creating a new topic with such a question.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •