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
![]() |
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 |
-
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, 2 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
-
Help with WD usb driver on Windows 11
by
Tex265
59 minutes ago -
hibernate activation
by
e_belmont
1 hour, 48 minutes ago -
Red Hat Enterprise Linux 10 with AI assistant
by
Alex5723
5 hours, 36 minutes ago -
Windows 11 Insider Preview build 26200.5603 released to DEV
by
joep517
8 hours, 41 minutes ago -
Windows 11 Insider Preview build 26120.4151 (24H2) released to BETA
by
joep517
8 hours, 42 minutes ago -
Fixing Windows 24H2 failed KB5058411 install
by
Alex5723
11 hours, 52 minutes ago -
Out of band for Windows 10
by
Susan Bradley
13 hours, 25 minutes ago -
Giving UniGetUi a test run.
by
RetiredGeek
20 hours, 23 minutes ago -
Windows 11 Insider Preview Build 26100.4188 (24H2) released to Release Preview
by
joep517
1 day, 4 hours ago -
Microsoft is now putting quantum encryption in Windows builds
by
Alex5723
1 day, 1 hour ago -
Auto Time Zone Adjustment
by
wadeer
1 day, 8 hours ago -
To download Win 11 Pro 23H2 ISO.
by
Eddieloh
1 day, 6 hours ago -
Manage your browsing experience with Edge
by
Mary Branscombe
10 hours, 44 minutes ago -
Fewer vulnerabilities, larger updates
by
Susan Bradley
21 hours, 40 minutes ago -
Hobbies — There’s free software for that!
by
Deanna McElveen
5 hours, 34 minutes ago -
Apps included with macOS
by
Will Fastie
3 hours, 26 minutes ago -
Xfinity home internet
by
MrJimPhelps
13 minutes ago -
Convert PowerPoint presentation to Impress
by
RetiredGeek
1 day, 1 hour ago -
Debian 12.11 released
by
Alex5723
2 days, 5 hours ago -
Microsoft: Troubleshoot problems updating Windows
by
Alex5723
2 days, 9 hours ago -
Woman Files for Divorce After ChatGPT “Reads” Husband’s Coffee Cup
by
Alex5723
1 day, 12 hours ago -
Moving fwd, Win 11 Pro,, which is best? Lenovo refurb
by
Deo
7 minutes ago -
DBOS Advanced Network Analysis
by
Kathy Stevens
3 days, 2 hours ago -
Microsoft Edge Launching Automatically?
by
healeyinpa
2 days, 16 hours ago -
Google Chrome to block admin-level browser launches for better security
by
Alex5723
14 hours, 21 minutes ago -
iPhone SE2 Stolen Device Protection
by
Rick Corbett
2 days, 21 hours ago -
Some advice for managing my wireless internet gateway
by
LHiggins
2 days, 4 hours ago -
NO POWER IN KEYBOARD OR MOUSE
by
HE48AEEXX77WEN4Edbtm
1 day, 6 hours ago -
A CVE-MITRE-CISA-CNA Extravaganza
by
Nibbled To Death By Ducks
3 days, 14 hours ago -
Sometimes I wonder about these bots
by
Susan Bradley
1 day, 2 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.