Consulting

Results 1 to 3 of 3

Thread: VBA for replace Font with specific Text

  1. #1
    VBAX Newbie
    Joined
    Apr 2021
    Location
    Rajasthan
    Posts
    4
    Location

    VBA for replace Font with specific Text

    Hi,
    I want to replace specific text font name to other font name. I am trying to write a macro for it. but font name not working here. please help and give a suggestion for it. sorry for bad grammer.

    Sub ReplaceTextWithFormatting()
         
        For Each myStoryRange In ActiveDocument.StoryRanges
            With myStoryRange.Find
            
                .ClearFormatting
                .Text = "wiki"
                .Font.Name = "Arial"
                .Replacement.ClearFormatting
                .Replacement.Text = "Romil"
                .Wrap = wdFindContinue
                .MatchCase = True
                .MatchWholeWord = True
                .ClearFormatting
                .Replacement.Font.Name = "Kokila"
                .Replacement.Font.Bold = True
                .Replacement.Font.Size = 18
                .Replacement.Font.Subscript = True
                .Replacement.Font.Color = RGB(0, 0, 255)
                .Execute Replace:=wdReplaceAll
         
            End With
         
        Next myStoryRange
         
    End Sub
    Last edited by macropod; 04-22-2021 at 02:25 PM. Reason: Added code tags

  2. #2
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    Replace your " expressions with actual plain double-quotes.

    You should also specify:
    .Format = True

    PS: When posting code, please usethe code tags, indicated by the # button on the posting menu. Without them,your code loses much of whatever structure it had.
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

  3. #3
    VBAX Newbie
    Joined
    Apr 2021
    Location
    Rajasthan
    Posts
    4
    Location

    Red face

    Quote Originally Posted by macropod View Post
    Replace your " expressions with actual plain double-quotes.

    You should also specify:
    .Format = True

    PS: When posting code, please usethe code tags, indicated by the # button on the posting menu. Without them,your code loses much of whatever structure it had.
    Thanks a lot
    It work.

Tags for this Thread

Posting Permissions

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