Link to home
Create AccountLog in
Avatar of Jeff McClellan
Jeff McClellanFlag for United States of America

asked on

VBA code that loops through a document to find defined text in a text string, go to the end of that text string, and insert a character (~) before/after the next paragraph mark

I want to use VBA / Word macro that will add a "~" character (or some unique symbol) at the end of every line where "http://" occurs and before/after the next line break/paragraph mark.  

1.  Search for an instance of the search text.  In this case "http://"
2. Find the next paragraph mark (line break) immediately after the search text.
3. Insert a "~" character immediately before (or after) the paragraph mark (line break).

Here is an example of the text I want to apply that to:

Ag Analytical Services Lab
• Soil Program 4x Year
Spargo, John T.
University Park, PA, 16802
Tel: 814-863-0841
Fax: 814-863-4540
AGAT Laboratories - Burnaby
• Soil and Plant Program
Pahl, Mackenzie
Burnaby, BC, V5J 0B6
Tel: 778-452-4000
Fax: 778-452-4074
AGAT Laboratories - Mississauga
• Soil and Plant Program 2x Year
Boulton, Nick
Mississauga, ON, L4Z 1Y2
Tel: 905-712-5075
Fax: 905-501-0589
AgLab Express
• Soil and Plant Program
Barber, Michael
Sioux Falls, SD, 57105-6411
Tel: 605-271-9237
Fax: 605-271-9238
Avatar of Paul Cook-Giles
Paul Cook-Giles
Flag of United States of America image

Link to home
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of Jeff McClellan


Works like a charm