|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
VBA wildcard search that only identifies results that do not follow delineated words
I am adding a routine to some VBA code to search for instances of a period that is followed by one space and then [0-9A-z] to identify the start of a new sentence. This is being done to identify instances of one space rather than two between sentences.
However, there are some obvious cases such as abbreviations mid-sentence that require periods, Mrs./Mr./etc. and others that will flag using the wildcard search for the above terms but should not have a double space following the period. Is it possible to condition a wildcard search to only return results if it does not follow a word found on a delineated list of words? |
#2
|
||||
|
||||
Word is not a typewriter. Sentences should only have one space.The following will remove additional spaces.
Code:
Sub Macro1() With Selection.Find .ClearFormatting .Replacement.ClearFormatting .Text = "^032{2,}" .Replacement.Text = " " .Forward = True .Wrap = wdFindContinue .Format = False .MatchCase = False .MatchWholeWord = False .MatchAllWordForms = False .MatchSoundsLike = False .MatchWildcards = True .Execute Replace:=wdReplaceAll End With End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
#3
|
|||
|
|||
As someone whose employer's in-house style used to mandate two spaces after a period, I understand the need.
You could certainly write a macro to test each found instance of a potential abbreviation to see if it matches an abbreviation list, but I don't think it's going to be accurate unless you put some effort into figuring out dealing with the abbreviations that could easily come at the end of a sentence: appt., Ave., corp., dept., et al., etc., Inc., and more Also, you'd need to figure out two-letter abbreviations, like a.m./p.m., which could also easily come at the end of a sentence. Or not. If your wildcard string finds text followed by a period, you'll need to also need a wildcard string that looks for strings with two periods, e.g., "a.m." and others, and another list of those abbreviations. You could get partway there by setting Word to show instances of one space after a period -- partway there because it's not fully accurate. |
#4
|
||||
|
||||
This Greg Maxey macro shows a method of dealing with name initials like George W. Bush Space After Sentences
You could expand on that to deal with the other edge cases such as Mr. You can include grammar check highlights to help spot inconsistencies. See An Automatic Two Spaces after a Period (Microsoft Word)
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#5
|
|||
|
|||
Thank you for your opinion on the matter. Your reply was, however, non responsive to the question at hand. When a person (me, in this case) is told how something is expected be done, that is how it is to be done. In this case, that means two spaces between sentences, regardless of personal opinions on the matter.
|
Thread Tools | |
Display Modes | |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Wildcard Search | gmaxey | Word VBA | 4 | 07-12-2020 05:13 PM |
Word VBA wildcard search - odd results | MikeForward | Word VBA | 3 | 02-21-2019 06:18 AM |
Change characters outside a wildcard while keeping wildcard results | nymusicman | Word VBA | 2 | 04-10-2014 08:17 AM |
2013 search results take a long time - they fill in as results in reverse date order | themookman | Outlook | 0 | 10-11-2013 12:01 PM |
Wildcard search help. | Kempston | Word | 0 | 11-13-2009 03:58 AM |