VBA to replace Bold Font with html tags within cells with non bold font

mtkapp27

New Member
Joined
Jul 13, 2017
Messages
2
I am trying to create a Excel VBA Macro to find bold text within cells with non bold text and add html bold tags around the original bold text and leave the non bold text alone. Example:
Find:
"This bold word"
and
Replace with:
"This <code style="margin: 0px; padding: 1px 5px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; font-size: 13px; line-height: inherit; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; vertical-align: baseline; background-color: rgb(239, 240, 241); white-space: pre-wrap;"><b>bold</b></code> word" (both html tags and word need to be bold)

It is very important to note the the bold text is within cells with non bold text and only the bold text should be replaced with bold and html tags. All Cell font must be kept.
I will also need a macro to convert the other way as well. Meaning find bold tags (<code style="margin: 0px; padding: 1px 5px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; font-size: 13px; line-height: inherit; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; vertical-align: baseline; background-color: rgb(239, 240, 241); white-space: pre-wrap;"><b></b></code>) with or without bold font itself and remove the tags and ensure the text is bold.

I don't even care if it is a find/replace or if it is found in one document and created in a new document or sheet with the modification.

Closest VBA I could find online to achieve this:
https://www.mrexcel.com/forum/excel...replace-loses-text-properties-formatting.html
[word] Find.execute On Individual Basis

but not what I need.

Please help.

 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
My post is not displaying the html tags as expected. The replaced text in excel needs to contain the actual < b > tags.
 
Upvote 0

Forum statistics

Threads
1,223,214
Messages
6,170,771
Members
452,353
Latest member
strainu

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top