Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 09-17-2021, 09:47 AM
rekent rekent is offline VBA wildcard search that only identifies results that do not follow delineated words Windows 10 VBA wildcard search that only identifies results that do not follow delineated words Office 2016
Novice
VBA wildcard search that only identifies results that do not follow delineated words
 
Join Date: May 2014
Posts: 22
rekent is on a distinguished road
Default 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?
Reply With Quote
  #2  
Old 09-17-2021, 10:46 PM
gmayor's Avatar
gmayor gmayor is offline VBA wildcard search that only identifies results that do not follow delineated words Windows 10 VBA wildcard search that only identifies results that do not follow delineated words Office 2019
Expert
 
Join Date: Aug 2014
Posts: 3,576
gmayor is a splendid one to beholdgmayor is a splendid one to beholdgmayor is a splendid one to beholdgmayor is a splendid one to beholdgmayor is a splendid one to beholdgmayor is a splendid one to behold
Default

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
Reply With Quote
  #3  
Old 09-18-2021, 02:35 PM
Peterson Peterson is offline VBA wildcard search that only identifies results that do not follow delineated words Windows 10 VBA wildcard search that only identifies results that do not follow delineated words Office 2019
Advanced Beginner
 
Join Date: Jan 2017
Posts: 86
Peterson is on a distinguished road
Default

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.
Reply With Quote
  #4  
Old 09-19-2021, 04:22 PM
Guessed's Avatar
Guessed Guessed is offline VBA wildcard search that only identifies results that do not follow delineated words Windows 10 VBA wildcard search that only identifies results that do not follow delineated words Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 2,638
Guessed is a splendid one to beholdGuessed is a splendid one to beholdGuessed is a splendid one to beholdGuessed is a splendid one to beholdGuessed is a splendid one to beholdGuessed is a splendid one to beholdGuessed is a splendid one to behold
Default

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
Reply With Quote
  #5  
Old 09-23-2021, 10:55 AM
rekent rekent is offline VBA wildcard search that only identifies results that do not follow delineated words Windows 10 VBA wildcard search that only identifies results that do not follow delineated words Office 2016
Novice
VBA wildcard search that only identifies results that do not follow delineated words
 
Join Date: May 2014
Posts: 22
rekent is on a distinguished road
Default

Quote:
Originally Posted by gmayor View Post
Word is not a typewriter. Sentences should only have one space.The following will remove additional spaces.
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.
Reply With Quote
Reply

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
VBA wildcard search that only identifies results that do not follow delineated words 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

Other Forums: Access Forums

All times are GMT -7. The time now is 01:53 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2021, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2021 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft