How can I get VBA to determine the point where Word will place a line break in a string? I want to control where the line breaks, by finding the last instance of a certain character before Wordโs line break and replacing that character with โChr(13)โ. The idea is to have a string formatted before it prints.
![]() |
Patch reliability is unclear. Unless you have an immediate, pressing need to install a specific patch, don't do it. |
SIGN IN | Not a member? | REGISTER | PLUS MEMBERSHIP |
-
VBA to find where Word will put a line break
Home » Forums » AskWoody support » Productivity software by function » MS Word and word processing help » VBA to find where Word will put a line break
- This topic has 8 replies, 3 voices, and was last updated 12 years, 9 months ago.
Viewing 3 reply threadsAuthorReplies-
WSBigMac56
AskWoody Lounger -
WSStylus
AskWoody LoungerSeptember 12, 2012 at 9:57 am #1348819Yes, Word wraps dependent on where the margins are – at the margin, regardless of the content it is wrapping.
I want to use VBA to insert a line break so that I can control where in the text the break happens. If I can figure out where the word wrap will happen, then I can search back through the text string from the wrapping point, until I find the spot where I prefer the break to happen.
Here’s my situation: I have a string of varying length. It contains a series of data, separated by a forward slash. Sometime this string is so long that Word wraps the line. When that happens, the line is broken not at a slash, but anywhere. Often the wrap happens in the middle of a bit of data.
If I know where Word will wrap the line (if it’s too long), then I can search backwards from that point until I find the first slash, and then replace that slash with a line break. That way, when the string actually prints, the line will break without splitting one of my bits of data.
-
WSBigMac56
AskWoody LoungerSeptember 12, 2012 at 10:31 am #1348823Assuming that your data string will include spaces, you could use non breaking spaces.
See http://office.microsoft.com/en-us/word-help/use-nonbreaking-spaces-and-nonbreaking-hyphens-in-word-HA001044897.aspxIf that’s not the case you may want to switch to a mono space font like courier to ease calculations, since most Word fonts are proportional and the space used by letters varies.
-
-
Andrew Lockton
AskWoody_MVPSeptember 12, 2012 at 6:16 pm #1348844BigMac is on the right track but I don’t think non-breaking spaces is going to work.
There is a character for this purpose. It is called a No-Width Optional Break and can be found in Insert > Symbol > Special Characters.
I would try replacing every forward slash with a forward slash + No-Width Optional Break
-
WSStylus
AskWoody LoungerSeptember 13, 2012 at 2:25 am #1348868BigMac56 & Andrew
Thank you. The thing is that the slashes are for human eyeballs, so replacing them won’t work.
However… I could combine the slash with the NWOB! I just googled that thought and found an article at TechRepublic to that effect:
Now all I have to do is chose whether I want a slash at the end of a line or at the beginning of the next line. Neither ideal, but much better than splitting my data!
I like this tool a lot, it’s a kind of conditional formatting that makes it possible to build strings with VBA, and then print ’em with no fear of Word’s ‘Sword of Doom’ word wrapping.
Thanks all for your input!
-
WSStylus
AskWoody LoungerSeptember 13, 2012 at 11:27 am #1348907aaaah, I was a bit hasty there…
By recording a macro I found that the code for the No-Width Optional Break symbol is 8204. I attempted to insert that into my macro-generated string by writing
StringName = blabla & “/” & Chr(8204). This compiled ok, yet the result baffles me: the entire string either fails to print or prints out blank!
So: am I using the wrong method for inserting the character, or is there something else afoot?
-
Andrew Lockton
AskWoody_MVPWSStylus
AskWoody LoungerViewing 3 reply threads -

Plus Membership
Donations from Plus members keep this site going. You can identify the people who support AskWoody by the Plus badge on their avatars.
AskWoody Plus members not only get access to all of the contents of this site -- including Susan Bradley's frequently updated Patch Watch listing -- they also receive weekly AskWoody Plus Newsletters (formerly Windows Secrets Newsletter) and AskWoody Plus Alerts, emails when there are important breaking developments.
Get Plus!
Welcome to our unique respite from the madness.
It's easy to post questions about Windows 11, Windows 10, Win8.1, Win7, Surface, Office, or browse through our Forums. Post anonymously or register for greater privileges. Keep it civil, please: Decorous Lounge rules strictly enforced. Questions? Contact Customer Support.
Search Newsletters
Search Forums
View the Forum
Search for Topics
Recent Topics
-
Recommended watching : Mountainhead movie
by
Alex5723
1 hour, 43 minutes ago -
End of support for Windows 10
by
Old enough to know better
2 minutes ago -
What goes on inside an LLM
by
Michael Covington
1 hour, 33 minutes ago -
The risk of remote access
by
Susan Bradley
38 minutes ago -
The cruelest month for many Office users
by
Peter Deegan
1 hour, 1 minute ago -
Tracking protection and trade-offs in Edge
by
Mary Branscombe
3 hours, 57 minutes ago -
Supreme Court grants DOGE access to confidential Social Security records
by
Alex5723
10 hours, 34 minutes ago -
EaseUS Partition Master free 19.6
by
Alex5723
2 hours, 30 minutes ago -
Microsoft : Edge is better than Chrome
by
Alex5723
23 hours, 50 minutes ago -
The EU launched DNS4EU
by
Alex5723
1 day, 12 hours ago -
Cell Phone vs. Traditional Touchtone Phone over POTS
by
280park
1 day, 2 hours ago -
Lost access to all my networked drives (shares) listed in My Computer
by
lwerman
1 day, 17 hours ago -
Set default size for pasted photo to word
by
Cyn
2 days ago -
Dedoimedo tries 24H2…
by
Cybertooth
1 day, 12 hours ago -
Windows 11 Insider Preview build 27871 released to Canary
by
joep517
2 days, 22 hours ago -
Windows 11 ad from Campaign Manager in Windows 10
by
Jim McKenna
15 hours, 45 minutes ago -
Small desktops
by
Susan Bradley
14 hours, 51 minutes ago -
Totally disable Bitlocker
by
CWBillow
1 day, 16 hours ago -
Phishers extract Millions from HMRC accounts..
by
Microfix
2 days, 20 hours ago -
Windows 10 22H2 Update today (5 June) says up-to-date but last was 2025-04
by
Alan_uk
4 days, 2 hours ago -
Thoughts on Malwarebytes Scam Guard for Mobile?
by
opti1
1 day, 21 hours ago -
Mystical Desktop
by
CWBillow
4 days, 6 hours ago -
Meta and Yandex secretly tracked billions of Android users
by
Alex5723
3 days, 11 hours ago -
MS-DEFCON 2: Do you need that update?
by
Susan Bradley
22 hours, 50 minutes ago -
CD/DVD drive is no longer recognized
by
WSCape Sand
4 days, 21 hours ago -
Windows 11 24H2 Default Apps stuck on Edge and Adobe Photoshop
by
MikeBravo
5 days ago -
North Face and Cartier customer data stolen in cyber attacks
by
Alex5723
4 days, 22 hours ago -
What is wrong with simple approach?
by
WSSpoke36
2 days, 20 hours ago -
Microsoft-Backed Builder.ai Set for Bankruptcy After Cash Seized
by
Alex5723
5 days, 9 hours ago -
Location, location, location
by
Susan Bradley
4 days ago
Recent blog posts
Key Links
Want to Advertise in the free newsletter? How about a gift subscription in honor of a birthday? Send an email to sb@askwoody.com to ask how.
Mastodon profile for DefConPatch
Mastodon profile for AskWoody
Home • About • FAQ • Posts & Privacy • Forums • My Account
Register • Free Newsletter • Plus Membership • Gift Certificates • MS-DEFCON Alerts
Copyright ©2004-2025 by AskWoody Tech LLC. All Rights Reserved.