I am wanting to get some data from an Excel spreadsheet. My problem is the data in the cell has been formatted.

i.e. This is sample text.

I want to be able to know which bits are made bold and create a string similar to: This is <b>sample<\b> text.

I canb get the text from the cell but lose the formatting.

Any ideas??

Happy New Year!


8 Years
Discussion Span
Last Post by Comatose

I worked out one solution - its a bit slow but works.

myCell = "A3"
                OneChar = 0
                With objWorksheet.Range(myCell)
                    For i = 1 To .Characters.Count
                        With .Characters(i, 1).Font
                            ' Add the start tag <b>
                            If .Bold = True And boldON = False Then
                                FullRecord = FullRecord & "<b>"
                                boldON = True
                            End If
                            ' Add the end tag <\b>
                            If .Bold = False And boldON = True Then
                                FullRecord = FullRecord & "<\b>"
                                boldON = False
                            End If
                        End With
                        ' Increment character counter
                        OneChar = OneChar + 1
                        ' Add the character to the FullRecord variable
                        FullRecord = FullRecord & Mid$(.Characters.Text, OneChar, 1)
                    Next i
                    ' If all the cell is bold then the end tag needs to be added
                    If .Bold = True Then
                        FullRecord = FullRecord & "<\b>"
                        boldON = False
                    End If
                End With


Votes + Comments
Nice Code

That's Really Great Work. Not only did you solve your own issue, but you also showed us a valid, and clean way to do it. Great Job pG.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.