Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #16  
Old 02-28-2020, 11:39 AM
Eowyn Eowyn is offline Using find and replace to insert an extra space after full stops Mac OS X Using find and replace to insert an extra space after full stops Office 2016 for Mac
Novice
 
Join Date: Jun 2019
Location: New York
Posts: 23
Eowyn is on a distinguished road
Default

The grammar checker can help enforce 2 spaces. I don't care for it, but go to Word, preferences, Spelling and Grammar, check grammar (as you type/with spelling). Go to settings for grammar; on the REQUIRE change space between sentences from DON'T CHECK to 2 spaces.

Unfortunately, turning grammar checker slows things down a lot. You should probably clear a lot of what the grammar checker will stop/flag. Maybe all of the other settings??
Reply With Quote
  #17  
Old 02-28-2020, 11:47 AM
Charles Kenyon Charles Kenyon is offline Using find and replace to insert an extra space after full stops Windows 10 Using find and replace to insert an extra space after full stops Office 2019
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,138
Charles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant future
Default

You should also be checking for question marks and colons.
Reply With Quote
  #18  
Old 03-01-2020, 06:48 PM
Guessed's Avatar
Guessed Guessed is offline Using find and replace to insert an extra space after full stops Windows 10 Using find and replace to insert an extra space after full stops Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,977
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

I think there must be a way to automate this by using the Grammar check functionality. to demonstrate this go in to File>Options>Proofing>When correcting spelling and grammar in Word>Writing Style>Settings>Spaces required between sentences and set this to either 1 or 2
Now look at the blue underlined grammar issues on the page. You can see that Word does a good job of working out what a sentence is. It shouldn't be a stretch to make use of that to automate a grammar check that 'fixes' the one vs two space issue.
Attached Images
File Type: png GrammarCheck.png (60.0 KB, 29 views)
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #19  
Old 03-01-2020, 07:10 PM
macropod's Avatar
macropod macropod is offline Using find and replace to insert an extra space after full stops Windows 7 64bit Using find and replace to insert an extra space after full stops Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Quote:
Originally Posted by Guessed View Post
It shouldn't be a stretch to make use of that to automate a grammar check that 'fixes' the one vs two space issue.
Your mission, should you choose to accept it...
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #20  
Old 03-01-2020, 07:41 PM
Guessed's Avatar
Guessed Guessed is offline Using find and replace to insert an extra space after full stops Windows 10 Using find and replace to insert an extra space after full stops Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,977
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

Hey Paul, I'm just chipping in with ideas. I'm busy on a job in your hometown at the moment and won't have bandwidth to go exploring the code until after the weekend. My out of work time at the moment consists of an occasional walk on Red Hill or Mt Ainsley and that is all I have.

This problem has been around for 30+ years so another week won't kill anyone.
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #21  
Old 03-02-2020, 06:43 AM
Johanna Johanna is offline Using find and replace to insert an extra space after full stops Mac OS X Using find and replace to insert an extra space after full stops Office 2019
Novice
Using find and replace to insert an extra space after full stops
 
Join Date: Jun 2019
Location: Bristol
Posts: 28
Johanna is on a distinguished road
Default

Thanks everyone. Yeah, I've got the two spaces check turned on, but for some reason it doesn't seem to flag them up consistently. If I'm writing comments to the client and I don't put two spaces in, it flags them up. It rarely flags them up in the client's existing work until I place the cursor after the single spaces - and even then, it sometimes still doesn't. It's oddly inconsistent!



The document is nearly 300 pages long so I'm going to be working on it for a while longer. So far, eyeballing seems to be working OK, but I may be missing some, and it just feels like there MUST be a way to run a check for it.



Thanks for your help, all!
Reply With Quote
  #22  
Old 03-02-2020, 06:50 AM
Johanna Johanna is offline Using find and replace to insert an extra space after full stops Mac OS X Using find and replace to insert an extra space after full stops Office 2019
Novice
Using find and replace to insert an extra space after full stops
 
Join Date: Jun 2019
Location: Bristol
Posts: 28
Johanna is on a distinguished road
Default

But then I've just opened a different document and it's flagging single spaces every time! Weird!
Reply With Quote
  #23  
Old 03-02-2020, 08:46 AM
kilroyscarnival kilroyscarnival is offline Using find and replace to insert an extra space after full stops Windows 7 64bit Using find and replace to insert an extra space after full stops Office 2010
Expert
 
Join Date: May 2019
Posts: 345
kilroyscarnival is just really nicekilroyscarnival is just really nicekilroyscarnival is just really nicekilroyscarnival is just really nice
Default

Quote:
Originally Posted by Johanna View Post
Sadly Ann's method doesn't work either - just searching for a full stop followed by a single space finds all the full stops followed by double spaces, as they are technically followed by a single space - and then another single space!

Any other ideas?
That's actually why I needed a second step. Replacing ". " with ". " across all is going to usually yield a few where the stop is now followed by THREE spaces. Thus my second Replace of stop-three spaces with stop-two spaces. But where that makes extra work is in the cases within the doc where I actually wanted one space, like "Chris B. Gordon" and "Mr. Paul Wilson."

For me, I generally do all the other revisions in the document first, and try to keep an eye on how consistent/inconsistent the author has been in applying the spacing. If it's a large document and the single-spaces are all over, I may do the Replace All/Replace All sequence. Otherwise, I do a manual Find/Replace and hit Find Next if it's a break that doesn't need replacing.

There are lots of things I wish I could change about the way the department uses Word. For example, all their docs are set up with 0 before and after line spacing, so paragraphs are made by double return. When it comes to having to eyeball a document that may contain small and large tables, text boxes, images, and the like, this makes for some funky page breaks that would be eliminated by using the paragraph spacing. I suspect they may be susceptible to change when the senior partner eventually retires.
Reply With Quote
  #24  
Old 03-02-2020, 10:09 AM
kilroy kilroy is offline Using find and replace to insert an extra space after full stops Windows 10 Using find and replace to insert an extra space after full stops Office 2016
Competent Performer
 
Join Date: Sep 2016
Location: Southern Ontario
Posts: 118
kilroy is on a distinguished road
Default

All of my documents use default font color of black. So if you se other colors it may not work properly. I used 450 pages (2800 paragraphs) of the following example:

Each paragraph had either a . or an ! or a ? at he end of what we view as sentences.

"There is no Ms. simple programming solution for this? Although VBA has a'sentences' collection, that has no correlation with grammatical sentences? Forexample, consider the following: Mr. Smith spent $1,234.56 at Dr. John'sGrocery Store, to buy: 10.25kg of potatoes; 10kg of avocados; and 15.1kg of Mrs.Green's Mt. Pleasant macadamia nuts? For ETC. you and me, that would countas one sentence; for etc. VBA it counts as 5 sentences? "

It took around 2 minutes 40 seconds
(Code tags not working)

This works for me:
for some reason the lines with .Replacement.Text = "? " are removing the extra space it should have 2 spaces after the punctuation in all 3 scenarios.

Sub DoubleSpaceToEndSentence()
' Kilroy
Dim range As range
Dim i As Long
Dim TargetList
TargetList = Array("Mr.", "Mrs.", "Ms.", "etc.", "ETC.", "Dr.", "Mt.", "[0-9].[0-9]")
For ii = 0 To UBound(TargetList)
Set range = ActiveDocument.range
With range.Find
.Text = TargetList(ii)
.Format = True
.MatchCase = True
.MatchWholeWord = False
.MatchWildcards = True
.MatchSoundsLike = False
.MatchAllWordForms = False
Do While .Execute(Forward:=True) = True
range.Font.Color = vbBlue
Loop
End With
Next
Selection.Find.ClearFormatting
Selection.Find.Font.Color = Default
With Selection.Find
.Wrap = wdFindContinue
.MatchWildcards = False
.Text = ". "
.Replacement.Text = ". "
.Execute Replace:=wdReplaceAll
.Text = "! "
.Replacement.Text = "! "
.Execute Replace:=wdReplaceAll
.Text = "? "
.Replacement.Text = "? "
.Execute Replace:=wdReplaceAll
End With
Selection.WholeStory
With Selection
.Font.Color = Default
End With
End Sub
Reply With Quote
  #25  
Old 03-02-2020, 11:27 AM
kilroyscarnival kilroyscarnival is offline Using find and replace to insert an extra space after full stops Windows 7 64bit Using find and replace to insert an extra space after full stops Office 2010
Expert
 
Join Date: May 2019
Posts: 345
kilroyscarnival is just really nicekilroyscarnival is just really nicekilroyscarnival is just really nicekilroyscarnival is just really nice
Default

Quote:
Originally Posted by Johanna View Post
But then I've just opened a different document and it's flagging single spaces every time! Weird!

Here's a thought: ask your client to change his or her preferences to include the two space setting also?
Reply With Quote
  #26  
Old 03-02-2020, 02:01 PM
kilroy kilroy is offline Using find and replace to insert an extra space after full stops Windows 10 Using find and replace to insert an extra space after full stops Office 2016
Competent Performer
 
Join Date: Sep 2016
Location: Southern Ontario
Posts: 118
kilroy is on a distinguished road
Default

This approach works much faster. Again, in the .Replacement.Text = "! " the extra space after the punctuation is being removed for some reason. Add the extra space in all 3 instances


Sub DoubleSpaceToEndSentence2()
Dim Word As range
Dim WordCollection(7) As String
Dim Words As Variant
Selection.WholeStory
With Selection
.Font.Color = Default
End With
WordCollection(0) = "Mr. "
WordCollection(1) = "Mrs. "
WordCollection(2) = "Dr. "
WordCollection(3) = "Ms. "
WordCollection(4) = "Mt. "
WordCollection(5) = "etc. "
WordCollection(6) = "ETC. "
WordCollection(7) = "[0-9].[0-9]"
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
Selection.Find.Replacement.Font.Color = vbBlue
For Each Words In WordCollection
With Selection.Find
.Text = Words
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = True
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
Next
Selection.WholeStory
With Selection.Find
Selection.Find.ClearFormatting
Selection.Find.Font.Color = Default
Selection.Find.Replacement.ClearFormatting
Selection.Find.Replacement.Font.Color = Default
With Selection.Find
.Wrap = wdFindContinue
.MatchWildcards = False
.Text = ". "
.Replacement.Text = ". "
.Execute Replace:=wdReplaceAll
.Text = "! "
.Replacement.Text = "! "
.Execute Replace:=wdReplaceAll
.Text = "? "
.Replacement.Text = "? "
.Execute Replace:=wdReplaceAll
End With
Selection.WholeStory
With Selection
.Font.Color = Default
End With
End With
End Sub
Reply With Quote
  #27  
Old 03-02-2020, 04:27 PM
macropod's Avatar
macropod macropod is offline Using find and replace to insert an extra space after full stops Windows 7 64bit Using find and replace to insert an extra space after full stops Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Once doesn't necessarily want to have only single spaces after abbreviations like 'etc.', since that (and others) actually sometimes conclude a sentence. Your Find/Replace could also be greatly simplified via the use of wildcards - and without creating three spaces where there are now two. For example:
Code:
Sub Demo()
Application.ScreenUpdating = False
With ActiveDocument.Range
  With .Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .Forward = True
    .Wrap = wdFindContinue
    .Format = False
    .MatchWildcards = True
    'First, clear out all existing double, triple, etc. spaces
    .Text = "[ ]{2,}"
    .Replacement.Text = " "
    .Execute Replace:=wdReplaceAll
    'Second, insert double spaces after every punctuation mark followed by a space then an upper-case letter
    .Text = "([.\?\!\:\;] )([A-Z])"
    .Replacement.Text = "\1 \2"
    .Execute Replace:=wdReplaceAll
    'Third, clean up common abbreviations
    .Text = "([DMS][rs]{1,2}. ) ([A-Z])"
    .Replacement.Text = "\1\2"
    .Execute Replace:=wdReplaceAll
    .Text = "(etc. ) ([a-z])"
    .Execute Replace:=wdReplaceAll
  End With
End With
Application.ScreenUpdating = True
End Sub
PS: When posting code, please use formatted code and the code tags, indicated by the # button on the posting menu. Without them, your code loses much of whatever structure it had.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #28  
Old 03-04-2020, 12:58 PM
kilroy kilroy is offline Using find and replace to insert an extra space after full stops Windows 10 Using find and replace to insert an extra space after full stops Office 2016
Competent Performer
 
Join Date: Sep 2016
Location: Southern Ontario
Posts: 118
kilroy is on a distinguished road
Default

Paul above code works great man! I still have much to learn about using wildcards. I say this in jest but what you and the other VBA wizards here call simplified actually hurts my rain sometimes. It also always raises more questions for newbies like me. Which I'm thankful for. You, Greg, Graham, Charles and a couple of others too over the last 2 1/2 years have made learning VBA just challenging enough to keep it super interesting. Thanks to all of you for your time and effort.
Reply With Quote
  #29  
Old 03-04-2020, 01:43 PM
Charles Kenyon Charles Kenyon is offline Using find and replace to insert an extra space after full stops Windows 10 Using find and replace to insert an extra space after full stops Office 2019
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,138
Charles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant future
Default

To me, wildcards are much harder than vba! That may be that I have not focused on it as much. Here are some of my resources. When those do not work, I come here.

Reply With Quote
  #30  
Old 03-04-2020, 01:55 PM
kilroy kilroy is offline Using find and replace to insert an extra space after full stops Windows 10 Using find and replace to insert an extra space after full stops Office 2016
Competent Performer
 
Join Date: Sep 2016
Location: Southern Ontario
Posts: 118
kilroy is on a distinguished road
Default

Thanks Charles!
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro for Find/replace to remove space before Hard Return AlfredStreich Word VBA 4 01-23-2020 03:59 PM
Using find and replace to insert an extra space after full stops Code to find numerical string + space throughout document & replace them with Comma Robert Kay Word VBA 6 02-21-2018 04:41 PM
Using find and replace to insert an extra space after full stops Find and Replace with space cheech1981 Word 3 03-29-2017 02:33 PM
Mac 2011 Word find/replace stops working jondic Word 0 08-31-2016 02:58 AM
Wildcard Find/Replace deletes extra character Cosmo Word 1 06-20-2014 08:49 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 08:03 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