Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I have some data that I pull from an external database and just
display it in an excel cell using VB. I currently strip out all of the html tags and convert the <br to line feeds. That works great. But I would like to convert <b tags within the cell to bold. So my cell might contain: "This is a <bformatting</b test." I am trying to figure out a way to make the word formatting in the example above bold. Can anyone help? Thanks, Matt |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
One way:
This assumes there's only one <b</b pair - you could use recursion if you expect more than one. Dim str As String Dim nBold As Long Dim nEndBold As Long Dim nChars As Long With ActiveCell str = .Text nBold = InStr(str, "<b") If nBold 0 Then nEndBold = InStr(str, "</b") If nEndBold = 0 Then nEndBold = 32767 nChars = nEndBold - nBold - 3 str = Replace(Replace(str, "<b", ""), "</b", "") .Value = str .Characters(nBold, nChars).Font.Bold = True End If End With For XL97 or MacXL, replace Replace with Application.Substitute In article , (Matt) wrote: I have some data that I pull from an external database and just display it in an excel cell using VB. I currently strip out all of the html tags and convert the <br to line feeds. That works great. But I would like to convert <b tags within the cell to bold. So my cell might contain: "This is a <bformatting</b test." I am trying to figure out a way to make the word formatting in the example above bold. Can anyone help? Thanks, Matt |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Turn on the macro recorder
Select a cell with text. go to the formula bar. Highlight just a subset of the text (similar to your example). go to format=Cells and select the font tab. Select Bold. Click OK and then hit enter to end the editing of the cell. Turn off the macro recorder. You will see that the code recorded uses the characters method to set the formatting options for a subset of a string. You should be able to adapt this to your situation. -- Regards, Tom Ogilvy "Matt" wrote in message om... I have some data that I pull from an external database and just display it in an excel cell using VB. I currently strip out all of the html tags and convert the <br to line feeds. That works great. But I would like to convert <b tags within the cell to bold. So my cell might contain: "This is a <bformatting</b test." I am trying to figure out a way to make the word formatting in the example above bold. Can anyone help? Thanks, Matt |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() This bit of code works for an individual cell: Sub OneLine() Dim First As Integer, Last As Integer, Length As Integer First = InStr(ActiveCell.Text, "<b") If First 0 Then Last = InStr(ActiveCell.Text, "</b") If Last 0 Then ActiveCell.Replace What:="<b", Replacement:="" ActiveCell.Replace What:="</b", Replacement:="" Length = Last - First - 3 ActiveCell.Characters(Start:=First, Length:=Length).Font.Bold = True End If End If End Sub HTH Helen -----Original Message----- I have some data that I pull from an external database and just display it in an excel cell using VB. I currently strip out all of the html tags and convert the <br to line feeds. That works great. But I would like to convert <b tags within the cell to bold. So my cell might contain: "This is a <bformatting</b test." I am trying to figure out a way to make the word formatting in the example above bold. Can anyone help? Thanks, Matt . |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Printing in excel always comes out in bold even tho bold not on | Excel Discussion (Misc queries) | |||
Alphabetically list of last names: BOLD, not bold | Excel Discussion (Misc queries) | |||
Alphabetically list of names BOLD and NOT bold | Excel Discussion (Misc queries) | |||
Excel if then bold | Excel Worksheet Functions | |||
Join bold and non-bold text in one cell | Excel Discussion (Misc queries) |