Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Converting <b to bold in excel

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default Converting <b to bold in excel

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Converting <b to bold in excel

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default Converting <b to bold in excel


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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Printing in excel always comes out in bold even tho bold not on Scarlett50 Excel Discussion (Misc queries) 2 March 26th 10 02:39 PM
Alphabetically list of last names: BOLD, not bold Lerner Excel Discussion (Misc queries) 16 March 1st 09 07:46 PM
Alphabetically list of names BOLD and NOT bold Lerner Excel Discussion (Misc queries) 13 March 1st 09 02:37 PM
Excel if then bold Bernie Excel Worksheet Functions 2 March 18th 08 09:25 PM
Join bold and non-bold text in one cell bkincaid Excel Discussion (Misc queries) 3 March 21st 06 12:58 AM


All times are GMT +1. The time now is 02:16 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"