ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   vba to convert htm tags (https://www.excelbanter.com/excel-programming/437153-vba-convert-htm-tags.html)

Southern at Heart

vba to convert htm tags
 
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


Rob van Gelder

vba to convert htm tags
 
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


Southern at Heart wrote:
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


ryguy7272

vba to convert htm tags
 
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--

--
Ryan---
If this information was helpful, please indicate this by clicking ''Yes''.


"Southern at Heart" wrote:

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



All times are GMT +1. The time now is 12:33 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com