I find that whenever I end a sentence with a colon it’s almost always to introduce a procedural step or a list of bullets, the first line of which I do not want to start on a new page. Rather than having to assign the KWN attribute or create a new style, is there a way to tell Word to automatically turn on KWN whenever a sentence ends with a colon?
![]() |
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 |
-
Automatically Assign Keep WIth Next (2003/SP2)
Home » Forums » AskWoody support » Productivity software by function » MS Word and word processing help » Automatically Assign Keep WIth Next (2003/SP2)
- This topic has 11 replies, 5 voices, and was last updated 16 years, 9 months ago.
Viewing 0 reply threadsAuthorReplies-
WSjscher2000
AskWoody LoungerSeptember 10, 2008 at 7:34 am #1125078I can’t think of any good way to do that. (AutoText can’t change formatting, AutoFormat As You Type doesn’t seem flexible enough, and creating a global macro to monitor every keystroke to watch for this would be overkill.)
You could create a macro that toggles the Keep with Next property and assign it to a keyboard shortcut for easier access.
-
WSgeoric1
AskWoody Lounger -
byteme
AskWoody PlusSeptember 11, 2008 at 5:01 am #1125123This macro will loop through a document and assign KWN to each paragraph that ends with a colon:
Dim oFind As Word.Find Set oFind = Selection.Find oFind.Text = ":^p" oFind.ClearFormatting Do While oFind.Execute = True Selection.ParagraphFormat.KeepWithNext = True Loop Set oFind = Nothing
-
WSgeoric1
AskWoody Lounger -
byteme
AskWoody PlusSeptember 11, 2008 at 4:59 am #1125173You may know this already, but I should have noted that Selection.Find is “sticky” in the sense that it retains various settings from one use to the next. So if you run the macro I posted and your previous search was limited to bold text, the macro will only find paragraphs ending in colons where the font at that point is bold.
To avoid this, it’s good practice to “clear” Selection.Find before you use it. Just adding Selection.Find.ClearFormatting may be good enough for your purposes (and I’ll be editing my previous post to add that line).
But if you want to be more thorough, you may want to create a separate “SetSearchDefaults” macro along the following lines and call it at the start of any macro that uses Selection.Find:
With Selection.Find .ClearFormatting .Replacement.ClearFormatting If .Format = True Then .Format = False End If If .Forward = False Then .Forward = True End If If .Wrap wdFindStop Then .Wrap = wdFindStop End If If .MatchCase = True Then .MatchCase = False End If If .MatchWholeWord = True Then .MatchWholeWord = False End If If .MatchWildcards = True Then .MatchWildcards = False End If If .MatchSoundsLike = True Then .MatchSoundsLike = False End If If .MatchAllWordForms = True Then .MatchAllWordForms = False End If End With
-
Andrew Lockton
AskWoody_MVPSeptember 13, 2008 at 12:19 pm #1125488I’m wondering why you bother with the If tests if you are going to set it to the opposite anyway?
Have you noticed a time lag in changing the settings that is not evident in the If statement? OR Are you only setting the sticky settings when they are not Nothing (the third Boolean possibility)?
-
byteme
AskWoody PlusSeptember 13, 2008 at 3:24 pm #1125511I’m not completely consistent on this issue, but my general prejudice (especially in “utility” macros that are going to see a lot of use because they get called by lots of other macros) is to avoid having Word actually do anything that isn’t necessary.
As one example, and as you probably know, applying a style to a paragraph can result in a blow-out of manual formatting that applies to more than 50% of the paragraph. And as you probably also know, if you apply a style to a paragraph with VBA, Word will re-apply the style (and potentially blow out manual formatting) even if the paragraph is already that same style.
Now, in the case you’ve specifically questioned, the unnecessary “re-application” I’m avoiding involves the Selection.Find object, rather than the document itself, and I’m not aware of any unwanted “side effects” (like the manual re-formatting problem) that might result from unnecessary manipulation of the .Find object, so I’ll grant you that my approach may well be overkill in that case. Still, it can’t hurt, and I guess the general rule would still apply — that the less a macro actually does, the less chance there is of an error.
-
WSHansV
AskWoody LoungerSeptember 13, 2008 at 9:31 pm #1125520I *think* that Andrew meant the following (he’ll correct me if I’m wrong): instead of
If .Format = True Then
.Format = False
End Ifyou could have used
.Format = False
The end result will be the same, and one wonders whether the time won by not setting .Format to False if it wasn’t false already outweighs the time lost by the potentially unnecessary If statement.
-
byteme
AskWoody PlusSeptember 14, 2008 at 5:29 am #1125556I think I interpreted Andrew’s post the same way you did. If .Format is already False and I use the simpler approach, Word may “reset” .Format. (I don’t know that it does, but I know it resets a paragraph’s style when you apply a style to a paragraph that already has that same style.) I agree that the “end result” is the same, but in one case Word has left the .Find object untouched and in the other case Word has performed an operation on the object.
In the case of a style reset, performing the operation can lead to unwanted consequences. As I said in my earlier post, I don’t know that there’s really any possibility of unwanted consequences (or errors) when Word “resets” a property of the .Find object, so my If tests may well be overkill..
-
WSHansV
AskWoody Lounger -
Andrew Lockton
AskWoody_MVPSeptember 14, 2008 at 11:55 am #1125585OK, thanks for taking the time to explain this, I can understand your reasoning now. Your methodology is more evolved than mine so you would tend to avoid more unforeseen events than I would typically encounter.
I would have to say that I nearly always take the shortest path when coding and only deal with the unforeseen problems which become evident during testing. If a problem hasn’t become evident in my limited testing then I have no qualms about letting others do the more detailed testing for me
Following your reasoning in the specific case which we are talking about, I would see your methodology being far more useful on the Replace settings rather than the Find settings. I remain unconvinced that your effort on the Find settings is warranted – but can see now the principle of why you are doing it. The only case where I (personally) would make a similar effort is where I wanted to leave the find settings in the same start state after my macro as they were prior to the macro running. Again, I tend to fall onto the laziness side for that too and don’t generally bother with that either.
-
-
-
-
Viewing 0 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
-
Apk on iphone (Awaiting moderation)
by
Calluum
1 hour, 54 minutes ago -
Are Macs immune?
by
Susan Bradley
5 hours, 8 minutes ago -
HP Envy and the Function keys
by
CWBillow
5 hours, 37 minutes ago -
Microsoft : Removal of unwanted drivers from Windows Update
by
Alex5723
7 hours, 1 minute ago -
MacOS 26 beta 1 dropped support for Firewire 400/800
by
Alex5723
7 hours, 18 minutes ago -
Unable to update to version 22h2
by
04om
7 hours, 38 minutes ago -
Windows 11 Insider Preview Build 26100.4482 (24H2) released to Release Preview
by
joep517
14 hours, 46 minutes ago -
Windows 11 Insider Preview build 27881 released to Canary
by
joep517
14 hours, 49 minutes ago -
Very Quarrelsome Taskbar!
by
CWBillow
38 minutes ago -
Move OneNote Notebook OFF OneDrive and make it local
by
CWBillow
1 day, 3 hours ago -
Microsoft 365 to block file access via legacy auth protocols by default
by
Alex5723
16 hours, 31 minutes ago -
Is your battery draining?
by
Susan Bradley
9 hours, 38 minutes ago -
The 16-billion-record data breach that no one’s ever heard of
by
Alex5723
6 hours, 37 minutes ago -
Weasel Words Rule Too Many Data Breach Notifications
by
Nibbled To Death By Ducks
1 day, 7 hours ago -
Windows Command Prompt and Powershell will not open as Administrator
by
Gordski
15 hours, 42 minutes ago -
Intel Management Engine (Intel ME) Security Issue
by
PL1
15 hours, 54 minutes ago -
Old Geek Forced to Update. Buy a Win 11 PC? Yikes! How do I cope?
by
RonE22
8 hours, 34 minutes ago -
National scam day
by
Susan Bradley
15 hours, 27 minutes ago -
macOS Tahoe 26 the end of the road for Intel Macs, OCLP, Hackintosh
by
Alex5723
11 hours, 36 minutes ago -
Cyberattack on some Washington Post journalists’ email accounts
by
Bob99
2 days, 8 hours ago -
Tools to support internet discussions
by
Kathy Stevens
21 hours, 22 minutes ago -
How get Group Policy to allow specific Driver to download?
by
Tex265
1 day, 23 hours ago -
AI is good sometimes
by
Susan Bradley
2 days, 15 hours ago -
Mozilla quietly tests Perplexity AI as a New Firefox Search Option
by
Alex5723
2 days, 5 hours ago -
Perplexity Pro free for 12 mos for Samsung Galaxy phones
by
Patricia Grace
3 days, 16 hours ago -
June KB5060842 update broke DHCP server service
by
Alex5723
3 days, 14 hours ago -
AMD Ryzen™ Chipset Driver Release Notes 7.06.02.123
by
Alex5723
3 days, 18 hours ago -
Excessive security alerts
by
WSSebastian42
2 days, 9 hours ago -
* CrystalDiskMark may shorten SSD/USB Memory life
by
Alex5723
4 days, 4 hours ago -
Ben’s excellent adventure with Linux
by
Ben Myers
18 hours, 25 minutes 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.