I'm developing a VBA function that will upload text from specific Excel range to a server. Since I'm also displaying the server data in a web app, I want to keep the source formatting (ie. if some words are bold in Excel, I want to keep that). For the moment, I only care about bold formatting. I developed the below solution, however it is extremely slow (converting a single cell with several sentences can take ~2 minutes). Looking to see if there is a faster way of achieving this.
Public Function getTextWithBold(rngText As Range) As String
Dim currentIsBold As Boolean
currentIsBold = False
Dim returnValue As String
returnValue = ""
For i = 1 To Len(rngText.Value)
If rngText.characters(i, 1).Font.Bold = True Then
If currentIsBold = False Then
currentIsBold = True
returnValue = returnValue & "<b>" & rngText.characters(i, 1).Text
Else
returnValue = returnValue & rngText.characters(i, 1).Text
End If
Else
If currentIsBold = True Then
currentIsBold = False
returnValue = returnValue & "</b>" & rngText.characters(i, 1).Text
Else
returnValue = returnValue & rngText.characters(i, 1).Text
End If
End If
If ((rngText.characters(i, 1).Font.Bold = True) And (i = Len(rngText.Value))) Then
returnValue = returnValue & "</b>"
End If
Next i
getTextWithBold = returnValue
End Function
RangetoHTML()function on this page