Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 09-26-2023, 10:39 PM
Dave T Dave T is offline Check if sentence ends with a full stop Windows 7 64bit Check if sentence ends with a full stop Office 2013
Advanced Beginner
Check if sentence ends with a full stop
 
Join Date: Nov 2014
Location: Australia
Posts: 66
Dave T is on a distinguished road
Default 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.
Reply With Quote
  #2  
Old 10-03-2023, 09:10 AM
East East is offline Check if sentence ends with a full stop Windows 10 Check if sentence ends with a full stop Office 2019
Novice
 
Join Date: Aug 2023
Posts: 7
East is on a distinguished road
Default

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
Reply With Quote
  #3  
Old 10-03-2023, 04:16 PM
Dave T Dave T is offline Check if sentence ends with a full stop Windows 7 64bit Check if sentence ends with a full stop Office 2013
Advanced Beginner
Check if sentence ends with a full stop
 
Join Date: Nov 2014
Location: Australia
Posts: 66
Dave T is on a distinguished road
Default

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
Now I have two options to use.
I appreciate your reply and helping me gain a better insight into the use of wildcards.
Regards, Dave T.
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Check if sentence ends with a full stop 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
Check if sentence ends with a full stop Word 2016 - Where's Sentence length check RightPaddock Word 1 08-22-2017 02:30 PM
Check if sentence ends with a full stop Open a video on full screen after I click on a sentence ALFA_ENG PowerPoint 1 11-06-2015 01:17 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 12:52 AM.


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