The “Replace” macro was based on Macropod’s code from “Conditional tied to trying to find a " " space character” (
https://www.msofficeforums.com/word-...character.html), which I adopted for a slightly different purpose. That purpose is to search for text entered in an input box in Word and test the character immediately in front of and following the target text. If it is not a space, enter a space, otherwise, ignore.
The Replace macro inserts a space in the front of the target. I added a variation so that the macro also inserts a space after the target text. Both work well except:
1. If the target is at the beginning of a sentence following a blank row.
2. If the target text’s case contains any upper case letters.
The case sensitivity is puzzling, especially when I’ve tried to shut it off on the code using MatchCase:=False and Option Compare Text. I want it to ignore case altogether.
The other effect I want is for the macro to read certain characters that follow the target text and if found, desist from inserting a space. I tried this by setting the characters below to the CharName variable and adding the Instr statement to see if it does the job, but it doesn’t work.
CharName = ",.?/\¬`!£$%^&*-+='@#~:;|<>¦-_{}[]()`¬'"
If InStr(1, CharName, SearchText) = 0 Then
.InsertAfter " "
I’ve attached a short Word doc with text for testing (highlighted in yellow) and a text file containing the macro (for some reason, this site no longer allows a .docm type file to be attached). If anybody has any suggestions for making it work as described above, please let me know. Thank you.