Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 03-26-2022, 02:17 PM
macropod's Avatar
macropod macropod is offline How do I find the last character in a line? Windows 10 How do I find the last character in a line? Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,359
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


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.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #2  
Old 03-26-2022, 10:31 PM
onlyif onlyif is offline How do I find the last character in a line? Windows 10 How do I find the last character in a line? Office 2021
Novice
How do I find the last character in a line?
 
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
Reply

Tags
find character, line



Similar Threads
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
How do I find the last character in a line? Find first character of a line Deferolles Word 11 04-26-2018 12:18 AM
How do I find the last character in a line? Delete Character on Single Line Only Tye30 Word VBA 8 04-20-2017 08:40 PM
How do I find the last character in a line? Every page indents first line one character glennhardy Word 6 02-05-2016 04:05 PM
How do I find the last character in a line? Use character instead of line for table border dlowrey Word Tables 6 03-09-2015 11:29 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 02:20 PM.


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