#1
|
|||
|
|||
Check if sentence ends with a full stop
Hello All,
I would prefer a macro to do this task as it will be incorporated into other macros. I have the following sentence "No restrictions apply". The first instance has a full stop/period after the word 'apply'. The next instance does not have a full stop after the word 'apply'. How can I find the sentence without the full stop/period and add a full stop/period to the end? I have been trying various wildcard combinations, without success as most of my attempts keep adding extra full stops/periods to those sentences with existing full stops/periods. Any suggestions will be appreciated. Regards, Dave T Last edited by Dave T; 09-27-2023 at 04:27 PM. |
#2
|
|||
|
|||
This should work, except when you have tables.
Code:
Sub AddFullStopToTerm() With ActiveDocument.Content.Find .ClearFormatting .Text = "(No restrictions apply)([!.])" .Replacement.ClearFormatting .Replacement.Text = "\1.\2" .Forward = True .Wrap = wdFindContinue .Format = False .MatchCase = False .MatchWholeWord = False .MatchWildcards = True .MatchSoundsLike = False .MatchAllWordForms = False .Execute Replace:=wdReplaceAll End With End Sub |
#3
|
|||
|
|||
Hello East,
I can’t thank you enough. I had been trying to work out the wildcard combinations for quite a while, without success. I had worked out breaking the parts within brackets and had the first part (No restrictions apply), but the second part where it may or may not have an existing full stop/period had me stumped. Not being that familiar with the use of wildcard characters was where I was stuck and I must admit I did not fully understand the use of the exclamation character ([!.]). After struggling with the wildcards option, I then thought I would try another approach and find the specific word/s in a paragraph and delete the entire paragraph and replace it with what I was after. That way if the line contained a full stop/period on not it would delete the entire line and replace it with what I was after. I found a reply by Greg Maxey to another post and edited this to suit my needs (link in code). Code:
Sub Add_Full_Stop_After_apply() 'https://www.msofficeforums.com/word-vba/45779-how-i-add-missing-stop-period-end.html Dim oRng As Range Set oRng = ActiveDocument.Range With oRng.Find '.Text = "[!.\!\?]" & Chr(13) .Text = "[apply]" & Chr(13) .MatchWildcards = True While .Execute oRng.Select oRng.Start = oRng.Start + 1 oRng.InsertBefore "." oRng.Collapse wdCollapseEnd Wend End With End Sub I appreciate your reply and helping me gain a better insight into the use of wildcards. Regards, Dave T. |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
How to suppress double ".." at the end of a sentence when a name ends "Inc." | dfolzenlogen | Mail Merge | 3 | 04-03-2022 08:49 PM |
How do I add a missing full stop / period at the end of a paragraph? | Helend269 | Word VBA | 2 | 10-08-2020 10:18 AM |
Let bookmark check if there are empty bookmarks before and place sentence there? | RevoMedia | Word VBA | 7 | 01-21-2020 08:04 AM |
Word 2016 - Where's Sentence length check | RightPaddock | Word | 1 | 08-22-2017 02:30 PM |
Open a video on full screen after I click on a sentence | ALFA_ENG | PowerPoint | 1 | 11-06-2015 01:17 AM |