While I was able to create a button to "reset" the font face and font size I'm encountering an error I didn't see before.
Here's the code for the module:
Code:
Public Function CleanRichText(strTEXT, strFont, nSize)
For i = 1 To 9
strTEXT = Replace(strTEXT, "size=" & i, "size=" & nSize)
Next i
strTEXT = Replace(strTEXT, "font face", "font_face")
strTEXT = Replace(strTEXT, "font" & Chr(13) & Chr(10) & "face", "font_face")
Do While InStr(1, strTEXT, "font_face=" & Chr(34)) > 0
iCut1 = InStr(1, strTEXT, "font_face=" & Chr(34))
iCut2 = InStr(iCut1 + 12, strTEXT, Chr(34))
strLeft = Left(strTEXT, iCut1 - 1) & "font_face=Face"
strRight = Right(strTEXT, Len(strTEXT) - iCut2)
strTEXT = strLeft & strRight
Loop
Do While InStr(1, strTEXT, "font_face=") > 0
iCut1 = InStr(1, strTEXT, "font_face=")
iCut2 = InStr(iCut1 + 12, strTEXT, Chr(32))
strLeft = Left(strTEXT, iCut1 - 1) & "font face=" & strFont & Chr(32)
strRight = Right(strTEXT, Len(strTEXT) - iCut2)
strTEXT = strLeft & strRight
Loop
CleanRichText = strTEXT
And the button:
Code:
Private Sub CleanTextBox_Click()
MsgBox ("Updating the comments to Arial 11pts")
Me.NOTES = CleanRichText(Me.NOTES, Me.NOTES.FontName, 2)
End Sub
When I had a sentence with text in a different colour in it it breaks the code.
For example here's what my unclean text looks like when it has colour in it:
Code:
<div><font face="Times New Roman" size=3>So basically any sentence</font><font face="Times New Roman" size=3 color=red>with </font><font face="Times New Roman" size=3>a color in it will break?</font></div>
And right after clicking the button:
Code:
<div><font face=Arial size=2>So basically any sentence </font><font face=Arial size=2 color=red>with </font><font face=Arial color in it will break?</font></div>
It looks like when the module is run against the colour it doesn't close.
Any ideas on how to fix this?