Find&Replace OpenType alternative characters with a macro

Stefano Bianque 21 Reputation points
2021-08-03T15:46:42.127+00:00

(I was recommended to ask my question here, so here it goes again)
https://answers.microsoft.com/en-us/msoffice/forum/msoffice_word-msoffice_custom-mso_365hp/findreplace-opentype-alternative-characters-with-a/de0d4100-1e31-4883-9896-9860de6c2abf

As the title says, is it possible to record a macro in MS Word that replaces the font's standard lowercase "a" to its alternative "a"?

I have no problems using the Find & Replace function, but recording it with the macro doesn't yield the desired result. And setting the alternative character as standard doesn't help either since it changes all other characters as well. I'm only interested in changing the lowercase "a" alone.

Thanks in advance for the help!
(Sorry if the tags are misleading, but I couldn't create new ones)

120090-aa.png

VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,596 questions
{count} votes

Accepted answer
  1. Viorel 112.9K Reputation points
    2021-08-04T13:29:59.483+00:00

    Try something like this:

    With ActiveDocument.Content.Find
        .ClearFormatting
        .Text = "a"
        With .Replacement
            .ClearFormatting
            .Font.StylisticSet = wdStylisticSet01
        End With
        .Execute Replace:=wdReplaceAll
    End With
    
    1 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Stefano Bianque 21 Reputation points
    2021-08-04T09:23:40.457+00:00

    This is the code I get when I record a macro. When I run said macro on a new text/document, it doesn't do anything.
    Just manually using the "Find & Replace"-function works without issues.

    Sub a()
    '
    ' a Makro
    ' alternativt a
    '
        Selection.Find.ClearFormatting
        Selection.Find.Replacement.ClearFormatting
        With Selection.Find
            .Text = "a"
            .Replacement.Text = "a"
            .Forward = True
            .Wrap = wdFindContinue
            .Format = True
            .MatchCase = False
            .MatchWholeWord = False
            .MatchWildcards = False
            .MatchSoundsLike = False
            .MatchAllWordForms = False
        End With
        Selection.Find.Execute Replace:=wdReplaceAll
    End Sub
    
    0 comments No comments