Forum Discussion
FabrizioBBG
Apr 13, 2023Copper Contributor
change the color of the last character in a shape text of excel sheet in VBA
Good morning
I would like to change the color of the last character in a shape text of excel sheet in VBA. The Shape is a button and the character on which to change the color is the check mark which is the last character. I can't figure out how to do it, I'm attaching a screenshot to better understand the situation and I'm adding the Sub code.
Public Sub DisegnaSpunta(ByVal lngRow As Long, ByVal strNomeBottone As String)
Application.ScreenUpdating = False
Dim strSpunta As String
Dim rngSpunta As Range
Dim testoBottone As String
With ActiveSheet
'Questo range serve solo per disegnare le righe sulla colonna G dove erano prima le spunte
strSpunta = .Cells(lngRow, "G").Address
Set rngSpunta = Range(strSpunta)
testoBottone = .Shapes.Range(Array(strNomeBottone)).TextFrame.Characters.Text & " " & ChrW(&H2713)
.Shapes.Range(Array(strNomeBottone)).TextFrame.Characters.Text = testoBottone
.Shapes.Range(Array(strNomeBottone)).TextFrame.Characters(Start:=Len(testoBottone) - 1, Length:=1).Font.Color = RGB(255, 0, 0)
CambiaBordiCella strSpunta
End With
Application.ScreenUpdating = True
End Sub
Thanks
Fabrizio
Change
.Shapes.Range(Array(strNomeBottone)).TextFrame.Characters(Start:=Len(testoBottone) - 1, Length:=1).Font.Color = RGB(255, 0, 0)
to
.Shapes.Range(Array(strNomeBottone)).TextFrame.Characters(Start:=Len(testoBottone), Length:=1).Font.Color = vbRed
Change
.Shapes.Range(Array(strNomeBottone)).TextFrame.Characters(Start:=Len(testoBottone) - 1, Length:=1).Font.Color = RGB(255, 0, 0)
to
.Shapes.Range(Array(strNomeBottone)).TextFrame.Characters(Start:=Len(testoBottone), Length:=1).Font.Color = vbRed