Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 05-28-2022, 03:27 PM
Frogoogue Frogoogue is offline How to code a Find&Replace macro to remove a tab and bold the entire para Windows 10 How to code a Find&Replace macro to remove a tab and bold the entire para Office 2019
Novice
How to code a Find&Replace macro to remove a tab and bold the entire para
 
Join Date: May 2022
Posts: 3
Frogoogue is on a distinguished road
Default How to code a Find&Replace macro to remove a tab and bold the entire para

I have a Word document with interviewer questions and answers
The format is like this:
<Interviewer:><^t><One or more sentence(s) with closing punctuation><^p>
and I want an MS Word Find and Replace macro to convert each instance into this:
<bold><Interviewer:><space><Identical One or more sentence(s) with closing punctuation><^p></bold>

The macro routine would look something like this:

Sub Reformat_Tabbed_Para()
'
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
Selection.Find.Replacement.Font.Bold = True
With Selection.Find


.Text = <><><><>
.Replacement.Text = "\1[space]\3\4"

.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute Replace:=wdReplaceAll
End Sub

I believe there is code allowing me to find and replace the same string of characters and punctuation up to the ^p but cannot find the correct way of writing it.
Help would be much appreciated!
Reply With Quote
  #2  
Old 05-28-2022, 04:20 PM
macropod's Avatar
macropod macropod is offline How to code a Find&amp;Replace macro to remove a tab and bold the entire para Windows 10 How to code a Find&amp;Replace macro to remove a tab and bold the entire para Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

It is not apparent from your post whether you're working with HTML strings, or whether what you've posted is simply your attempt to represent the document content in HTML format.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 05-29-2022, 04:02 AM
Frogoogue Frogoogue is offline How to code a Find&amp;Replace macro to remove a tab and bold the entire para Windows 10 How to code a Find&amp;Replace macro to remove a tab and bold the entire para Office 2019
Novice
How to code a Find&amp;Replace macro to remove a tab and bold the entire para
 
Join Date: May 2022
Posts: 3
Frogoogue is on a distinguished road
Default

My apologies, I thought that - since this is an MS Word VBA forum and I stated that I had a "Word document" and was looking for a solution using an "MS Word Find and Replace macro" - the expressions within chevrons would be understood to be the terms used in the F&R code given below.
Reply With Quote
  #4  
Old 05-29-2022, 06:55 AM
macropod's Avatar
macropod macropod is offline How to code a Find&amp;Replace macro to remove a tab and bold the entire para Windows 10 How to code a Find&amp;Replace macro to remove a tab and bold the entire para Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

In which case, you don't even need a macro - all you need is a single wildcard Find/Replace, where:
Code:
Find = (Interviewer:)^t([!^13]@^13)
Replace = \1 \2
with the bold attribute applied to the replacement.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #5  
Old 05-30-2022, 09:15 AM
Frogoogue Frogoogue is offline How to code a Find&amp;Replace macro to remove a tab and bold the entire para Windows 10 How to code a Find&amp;Replace macro to remove a tab and bold the entire para Office 2019
Novice
How to code a Find&amp;Replace macro to remove a tab and bold the entire para
 
Join Date: May 2022
Posts: 3
Frogoogue is on a distinguished road
Default

Thank you!
This - ([!^13]@^13) - is what I couldn't work out, was trying permutations involving (0-9A-z ) with 'ignore punctuation characters' specified, but it wasn't working.
Much appreciated!
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro for Find/replace to remove space before Hard Return AlfredStreich Word VBA 4 01-23-2020 03:59 PM
Create a macro or Find/Replace Code to delete tags bonzai217 Word 2 08-04-2019 08:36 AM
How to code a Find&amp;Replace macro to remove a tab and bold the entire para Macro to find and replace headings in bold and underline redzan Word VBA 4 02-13-2016 12:24 PM
Macro code that prompts user to enter text, then does find/replace. sfvegas PowerPoint 0 01-10-2016 08:02 PM
Looking for code to create a macro that prompts user to enter text, then does a find/replace. sfvegas PowerPoint 0 01-08-2016 02:22 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 03:56 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft