I’m trying to write a macro that puts a paragraph mark in front of every occurrence of the string “(x” where x is any letter but not a number. You can’t use the replace all box because it won’t work with wildcards. I bought a VBA book but still can’t figure out how to detect the last occurrence of the string in the open document and exit from whatever loop structure I’m using. Thanks in advance! – Randy
![]() |
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 |
-
Replace All Macro
Home » Forums » AskWoody support » Productivity software by function » MS Word and word processing help » Replace All Macro
- This topic has 16 replies, 10 voices, and was last updated 24 years, 3 months ago.
AuthorTopicWSrandywebb
AskWoody LoungerFebruary 20, 2001 at 3:27 am #353088Viewing 2 reply threadsAuthorReplies-
WSjscher2000
AskWoody Lounger -
WSGary Frieder
AskWoody LoungerFebruary 20, 2001 at 7:22 am #515446Hi Randy,
Here’s a macro I just wrote to replace one I’d had previously but lost!
It’s designed to do a Find/Replace continually as a loop until .Found is not True.
The purpose of this macro is to enable reducing all multiple spaces in a document to one space, without needing to re-run the replace.
Perhaps this could be adapted for your wildcard search:
{The ‘Do Until’ I had in there earlier was not necessary in this case; a simple Do does it.]Sub FindReplaceAllWithLoop() 'Gary Frieder February 2001 'Will reduce all extra spaces (2, 3, 4 etc.) to one space Do With Selection .HomeKey Unit:=wdStory With .Find .ClearFormatting .Replacement.ClearFormatting .Text = " " 'two spaces .Replacement.Text = " " 'one space .Forward = True .Wrap = wdFindStop 'important to use stop here .Format = False .MatchCase = False .MatchWholeWord = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False .Execute If .Found Then .Execute Replace:=wdReplaceAll Else Exit Sub End If End With End With Loop End Sub
Gary
-
WSPhil Rabichow
AskWoody LoungerFebruary 20, 2001 at 9:13 am #515456Hi Gary:
I don’t remember if I told you that Find/Replace would work in one fell swoop for this:
Using wildcards:
Find: “sp[2,]” w/o quotes, where sp= 1 space
Replace: “sp” w/o quotesThen do Replace All.
This says to find 2 or more spaces & replace them with one space.Hope this helps.
-
WSGary Frieder
AskWoody LoungerFebruary 21, 2001 at 5:26 am #515624Hi Phil,
I think you did… (shame on me). Because I still haven’t taken the time to sit down and properly learn how to use wildcards, whenever I see a tip relating to them, it seems to go into non-durable memory! Fields and wildcards are my particular bugbears.
Now, to help me get over this sad state: I recall your posting, some time back, and possibly in a different forum, a masterly compendium you’d put together relating to Find/Replace, including use of wildcards (I think you quoted Robin Trew heavily in that part) – have I got that right? If so, would you be willing to post the link to that one again? – I promise I will sit down and read it forwards and back until I’m programming wildcards in my sleep!
Gary
PS: I did need to remember how to do that loop again, anyway – useful for other things too.
-
WSPhil Rabichow
AskWoody LoungerFebruary 21, 2001 at 8:39 am #515633Hi Gary:
Here’s the link. I should again say that I quoted Robin Trew extensively, with her permission. In fact, the explanations are mostly hers & I put in lots of tables & examples. Download the 2nd file, if you have WinZip or something similar.
It’s at driveway.com. http://www.driveway.com/share?sid=b12f89b4…&name=Word+Tips
Driveway Shared WordTipsHope this helps.
-
Andrew Lockton
AskWoody_MVP -
WSGary Frieder
AskWoody LoungerFebruary 23, 2001 at 12:40 am #515918Hi Andrew,
On this delicate but amusing off-topic subject: I have to admit that in two years of posting here, as well as in the occasional personal correspondence I’ve had with Robin, I’ve always avoided the use of gender-specific pronouns, as I’ve never been sure!
Some time back, TomG did refer to Robin as “he”, and I might have done so in one post around that time.
Busy as Robin currently is, I know I’m not going to send a personal e-mail just to ‘pop the question’. Perhaps one of the real veterans around here (like Howard K.) can answer this one.(Y’know, this same issue could arise around any number of names…)
-
WSchrisgreaves
AskWoody Lounger -
WSgwhitfield
AskWoody Lounger -
WSgrugeon
AskWoody Lounger -
WSPhil Rabichow
AskWoody Lounger
-
-
-
-
WSPhil Rabichow
AskWoody Lounger-
mvpjjf
AskWoody PlusFebruary 21, 2001 at 3:04 am #515610Hi, Randy,
Forgive me if you already know this…
To use the Replace dialog with wildcards, you have to click the More button and check “Use wildcards”. Then you can use the Find and Replace strings Phil showed, and click Replace All.
You can also record a macro while you do this, so repeating it becomes a one-button job. You’ll see in the recorded code that the Selection.Find object has a .MatchWildcards property that is set to True, and the .Wrap property should be set to wdFindStop. The .Find.Execute method takes a Replace parameter that should be set to wdReplaceAll.
Jay
-
WSjscher2000
AskWoody Lounger -
WSRobin Kyd
AskWoody Lounger -
WSPhil Rabichow
AskWoody Lounger
-
Viewing 2 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
-
My Simple Word 2010 Macro Is Not Working
by
mbennett555
8 hours, 58 minutes ago -
Office gets current release
by
Susan Bradley
13 hours, 41 minutes ago -
FBI: Still Using One of These Old Routers? It’s Vulnerable to Hackers
by
Alex5723
1 day, 6 hours ago -
Windows AI Local Only no NPU required!
by
RetiredGeek
14 hours, 44 minutes ago -
Stop the OneDrive defaults
by
CWBillow
1 day, 7 hours ago -
Windows 11 Insider Preview build 27868 released to Canary
by
joep517
1 day, 16 hours ago -
X Suspends Encrypted DMs
by
Alex5723
1 day, 19 hours ago -
WSJ : My Robot and Me AI generated movie
by
Alex5723
1 day, 19 hours ago -
Botnet hacks 9,000+ ASUS routers to add persistent SSH backdoor
by
Alex5723
1 day, 20 hours ago -
OpenAI model sabotages shutdown code
by
Cybertooth
1 day, 20 hours ago -
Backup and access old e-mails after company e-mail address is terminated
by
M W Leijendekker
1 day, 8 hours ago -
Enabling Secureboot
by
ITguy
1 day, 15 hours ago -
Windows hosting exposes additional bugs
by
Susan Bradley
2 days, 4 hours ago -
No more rounded corners??
by
CWBillow
2 days ago -
Android 15 and IPV6
by
Win7and10
1 day, 14 hours ago -
KB5058405 might fail to install with recovery error 0xc0000098 in ACPI.sys
by
Susan Bradley
2 days, 16 hours ago -
T-Mobile’s T-Life App has a “Screen Recording Tool” Turned on
by
Alex5723
2 days, 19 hours ago -
Windows 11 Insider Preview Build 26100.4202 (24H2) released to Release Preview
by
joep517
2 days, 14 hours ago -
Windows Update orchestration platform to update all software
by
Alex5723
3 days, 2 hours ago -
May preview updates
by
Susan Bradley
2 days, 14 hours ago -
Microsoft releases KB5061977 Windows 11 24H2, Server 2025 emergency out of band
by
Alex5723
2 days, 5 hours ago -
Just got this pop-up page while browsing
by
Alex5723
2 days, 19 hours ago -
KB5058379 / KB 5061768 Failures
by
crown
2 days, 16 hours ago -
Windows 10 23H2 Good to Update to ?
by
jkitc
1 day, 18 hours ago -
At last – installation of 24H2
by
Botswana12
3 days, 18 hours ago -
MS-DEFCON 4: As good as it gets
by
Susan Bradley
16 hours, 13 minutes ago -
RyTuneX optimize Windows 10/11 tool
by
Alex5723
4 days, 6 hours ago -
Can I just update from Win11 22H2 to 23H2?
by
Dave Easley
2 days, 5 hours ago -
Limited account permission error related to Windows Update
by
gtd12345
4 days, 20 hours ago -
Another test post
by
gtd12345
4 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.