View Single Post
 
Old 03-26-2022, 10:31 PM
onlyif onlyif is offline Windows 10 Office 2021
Novice
 
Join Date: Mar 2022
Posts: 4
onlyif is on a distinguished road
Default

Quote:
Originally Posted by macropod View Post
You don't need a macro for that. All you need is a Find/Replace to change the space after a colon to a non-breaking space. If you do that, only the ones at the line ends will be visibly affected.

Likewise, you don't need macro to change plain quotes to smart quotes or vice-versa.

...welp, I feel like an idiot now. I didn't think about using a non-breaking space. And I had been wracking my brain about this for weeks!



My only follow-up concern is that a non-breaking space will work for colons, but not for em-dashes (—) and en-dashes (–), which wouldn't be followed by a space. Instead, those are followed by words—like this—so I'm not entirely sure how to fix that. My thought was that I'd do a search for the em-dash/en-dash, then move forward a word and replace that word with itself plus a non-breaking space, but I can't quite get the code to work.


Dim r As Range

Set r = ActiveDocument.Range
With r.Find
Do While .Execute(findtext:="—", Forward:=True) = True
With r
.Next(unit:=wdWord, Count:=1).Select

With Selection.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = "—"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False

With Selection
Dim thatword As String
thatword = Selection.Text
Selection.Find.Replacement.Text = thatword + "^160"

End With
End With
Selection.Find.Execute

Selection.Next(unit:=wdWord, Count:=1).Select

End With
r.Collapse direction:=wdCollapseEnd
Loop
End With


There's probably a simple error in that code...I just don't know what it is.



I know that I don't need to use a macro to change all the quotes because I could just do a find and replace, but since I have to do about a million find and replaces for a ton of different formatting things, I thought it might be easier to just make one big macro to do all of them at once.



The only other line-related thing that I'm completely stumped on is how I can detect when there are one-word lines (like in the example, where the word "utrices" is a single word on a line of its own), so that I can take some words from the previous line to move to that line to make sure no words are alone.



I know there are ways to detect one-word paragraphs, but I don't know about figuring that out for lines.



Is it even possible?
Reply With Quote