vba to convert htm tags

  • Thread starter Southern at Heart
  • Start date
S

Southern at Heart

I am needing to use VBA to do this:
Find every cell in my sheet that is bold, and replace it with "^b" plus
whatever text is in the cell, and another "^b"

I also need to do the reverse: find any cell that has ^b in it, and remove
the ^b, and make that cell bold

I've tried figuring this out with the record macro feature, but it doesn't
seem to record some of the find/replace features correctly when working with
finding the bold font.
thanks, southernatheart
 
R

Rob van Gelder

The problem might be easy if the entire cell was bold, but I suspect you want to bold just some of the text in a cell.

Some time ago I wrote something similar, which took what resembled html code, and applied it to an Excel cell.
http://vangelder.orcon.net.nz/excel/incellformat.zip

Let me know if that suits, otherwise reply and I'll see what can be done.

Cheers,
Rob
 
R

ryguy7272

Try this and let me know what you think:

Sub BoldFonts()
Dim SearchRange As Range, Cell As Range, BoldFonts As Range, x%
Set SearchRange = Cells.SpecialCells(xlCellTypeConstants)
For Each Cell In SearchRange
If Cell.Font.Bold = True Then
If x = 1 Then
Set BoldFonts = Union(BoldFonts, Cell)
Else
Set BoldFonts = Cell
x = 1
End If
End If
Next Cell
BoldFonts.Select

For Each c In Selection
If c.Value <> "" Then c.Value = "^b" & c.Value & "^b"
Next c

End Sub

Thanks!
Ryan--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top