![]() |
|
#1
|
|||
|
|||
![]() Quote:
...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? |
![]() |
Tags |
find character, line |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Header line only in text box using a different character set | anne4651 | Publisher | 0 | 07-03-2018 03:45 PM |
![]() |
Deferolles | Word | 11 | 04-26-2018 12:18 AM |
![]() |
Tye30 | Word VBA | 8 | 04-20-2017 08:40 PM |
![]() |
glennhardy | Word | 6 | 02-05-2016 04:05 PM |
![]() |
dlowrey | Word Tables | 6 | 03-09-2015 11:29 AM |