#16
|
|||
|
|||
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?? |
#17
|
|||
|
|||
You should also be checking for question marks and colons.
|
#18
|
||||
|
||||
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.
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#19
|
||||
|
||||
Your mission, should you choose to accept it...
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#20
|
||||
|
||||
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 |
#21
|
|||
|
|||
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! |
#22
|
|||
|
|||
But then I've just opened a different document and it's flagging single spaces every time! Weird!
|
#23
|
|||
|
|||
Quote:
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. |
#24
|
|||
|
|||
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 |
#25
|
|||
|
|||
Quote:
Here's a thought: ask your client to change his or her preferences to include the two space setting also? |
#26
|
|||
|
|||
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 |
#27
|
||||
|
||||
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
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#28
|
|||
|
|||
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.
|
#29
|
|||
|
|||
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.
|
#30
|
|||
|
|||
Thanks Charles!
|
|
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 |
Code to find numerical string + space throughout document & replace them with Comma | Robert Kay | Word VBA | 6 | 02-21-2018 04:41 PM |
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 |