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.
![]() |
There are isolated problems with current patches, but they are well-known and documented on this site. |
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, 8 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_MVP -
WSStylus
AskWoody Lounger
Viewing 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
-
Botnet hacks 9,000+ ASUS routers to add persistent SSH backdoor
by
Alex5723
13 minutes ago -
OpenAI model sabotages shutdown code
by
Cybertooth
50 minutes ago -
Backup and access old e-mails after company e-mail address is terminated
by
M W Leijendekker
13 minutes ago -
Enabling Secureboot
by
ITguy
3 hours, 59 minutes ago -
Windows hosting exposes additional bugs
by
Susan Bradley
8 hours, 44 minutes ago -
No more rounded corners??
by
CWBillow
4 hours, 32 minutes ago -
Android 15 and IPV6
by
Win7and10
9 hours, 49 minutes ago -
KB5058405 might fail to install with recovery error 0xc0000098 in ACPI.sys
by
Susan Bradley
21 hours, 5 minutes ago -
T-Mobile’s T-Life App has a “Screen Recording Tool” Turned on
by
Alex5723
23 hours, 47 minutes ago -
Windows 11 Insider Preview Build 26100.4202 (24H2) released to Release Preview
by
joep517
18 hours, 21 minutes ago -
Windows Update orchestration platform to update all software
by
Alex5723
1 day, 7 hours ago -
May preview updates
by
Susan Bradley
18 hours, 29 minutes ago -
Microsoft releases KB5061977 Windows 11 24H2, Server 2025 emergency out of band
by
Alex5723
10 hours, 4 minutes ago -
Just got this pop-up page while browsing
by
Alex5723
23 hours, 18 minutes ago -
KB5058379 / KB 5061768 Failures
by
crown
20 hours, 22 minutes ago -
Windows 10 23H2 Good to Update to ?
by
jkitc
4 hours, 55 minutes ago -
At last – installation of 24H2
by
Botswana12
1 day, 22 hours ago -
MS-DEFCON 4: As good as it gets
by
Susan Bradley
9 hours, 40 minutes ago -
RyTuneX optimize Windows 10/11 tool
by
Alex5723
2 days, 10 hours ago -
Can I just update from Win11 22H2 to 23H2?
by
Dave Easley
9 hours, 16 minutes ago -
Limited account permission error related to Windows Update
by
gtd12345
3 days ago -
Another test post
by
gtd12345
3 days ago -
Connect to someone else computer
by
wadeer
2 days, 18 hours ago -
Limit on User names?
by
CWBillow
2 days, 22 hours ago -
Choose the right apps for traveling
by
Peter Deegan
2 days, 11 hours ago -
BitLocker rears its head
by
Susan Bradley
1 day, 19 hours ago -
Who are you? (2025 edition)
by
Will Fastie
1 day, 18 hours ago -
AskWoody at the computer museum, round two
by
Will Fastie
2 days, 14 hours ago -
A smarter, simpler Firefox address bar
by
Alex5723
3 days, 10 hours ago -
Woody
by
Scott
3 days, 20 hours 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.