Hi,

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!

Pg

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

pG

commented: Nice Code +8

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.