Find & Replace special characters

Anonymous
2020-11-13T13:12:53+00:00

Hello,

I am trying to find & replace all words containing any of the following characters, and format them into a different font (EB Garamond, since normal Garamond font doesn't include them).

Special characters: ḍḏŷḥṭṯẓṣšāīūḌḎŶḤṬṮẒṢŠĀĪŪʿʾ

I've done a search with wildcards, searching for [ḍḏŷḥṭṯẓṣšāīūḌḎŶḤṬṮẒṢŠĀĪŪʿʾ] and replacing all characters with the wanted font. However, that only changes the characters, and I would like to change all the words containing those characters.

Is there a way of searching and replacing all words containing any of those characters?

Thank you very much,

Ignacio

Microsoft 365 and Office | Word | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

3 answers

Sort by: Most helpful
  1. Doug Robbins - MVP - Office Apps and Services 323.3K Reputation points MVP Volunteer Moderator
    2020-11-13T22:29:03+00:00

    Try using the following code in a macro

    Selection.HomeKey wdStory

    With Selection.Find

        Do While .Execute(FindText:="[ḍḏŷḥṭṯẓṣšāīūḌḎŶḤṬṮẒṢŠĀĪŪʿʾ]", Forward:=True, _

        MatchWildcards:=True, Wrap:=wdFindStop, MatchCase:=True) = True

            With Selection

                .Words(1).Font.Name = "EB Garamond"

                .Collapse wdCollapseEnd

            End With

        Loop

    End With

    End Sub

    Was this answer helpful?

    1 person found this answer helpful.
    0 comments No comments
  2. Stefan Blom 344.7K Reputation points MVP Volunteer Moderator
    2020-11-14T14:32:24+00:00

    There must be a Sub statement which corresponds with End Sub in Doug's example.

    You can type Sub MyFindandReplaceMacro on the line before Selection.HomeKey wdStory.

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2020-11-14T11:55:34+00:00

    Thank your for your anwser.

    I have created a macro and pasted the code but it shows like this, and then it says "invalid outside procedure". What should I do?

    Was this answer helpful?

    0 comments No comments