Macro de criação de forma no excel

Sub TEXTOBALÃO()
Dim shp As Shape
Dim texto As String
Dim regex As Object
Dim matches As Object
Dim match As Object
Dim numero As Double
Dim textoFormatado As String
Dim inicio As Integer
Dim comprimento As Integer
Dim cor As Long
Dim numeroFormatado As String
Dim startPos As Integer
Dim endPos As Integer
Dim cel As Range
Dim celulas As Variant
Dim i As Integer

celulas = Array(“C80”, “E80”, “G80”, “J80”, “L80”, “N80”, “Q80”, “S80”, “U80”, _
“C171”, “E171”, “G171”, “J171”, “L171”, “N171”, “Q171”, “S171”, “U171”)

Set regex = CreateObject(“VBScript.RegExp”)
regex.Global = True
regex.IgnoreCase = False
regex.Pattern = “-?\d+”

For i = LBound(celulas) To UBound(celulas)
Set cel = ActiveSheet.Range(celulas(i))
texto = cel.Value

textoFormatado = texto
Set matches = regex.Execute(texto)

For Each match In matches
numero = CDbl(match.Value)
numeroFormatado = “R$ ” & Format(Abs(numero) / 1000000, “0.0”) & ” M,”
textoFormatado = Replace(textoFormatado, match.Value, numeroFormatado)
Next match

Set shp = ActiveSheet.Shapes.AddShape(msoShapeRectangularCallout, cel.Left, cel.Top + cel.Height + 5, 150, 100)

With shp.Fill
.Visible = msoTrue
.ForeColor.ObjectThemeColor = msoThemeColorBackground1
.ForeColor.TintAndShade = 0
.ForeColor.Brightness = 0
.Transparency = 0
.Solid
End With

With shp.Line
.Visible = msoTrue
.ForeColor.RGB = RGB(255, 153, 153)
.Transparency = 0
.Weight = 0.25
End With

With shp.TextFrame2
.TextRange.text = textoFormatado
.TextRange.Font.Size = 7
.TextRange.Font.Fill.ForeColor.RGB = RGB(166, 166, 166)
.TextRange.ParagraphFormat.Alignment = msoAlignCenter
.VerticalAnchor = msoAnchorMiddle
End With

startPos = InStr(textoFormatado, “R$”)

For Each match In matches
If startPos > 0 Then
endPos = InStr(startPos + 3, textoFormatado, ” M,”)

If endPos > 0 Then
If CDbl(match.Value) < 0 Then
cor = RGB(192, 0, 0)
Else
cor = RGB(0, 128, 0)
End If

shp.TextFrame2.TextRange.Characters(startPos, endPos – startPos + 3).Font.Fill.ForeColor.RGB = cor
End If
End If
startPos = InStr(startPos + 1, textoFormatado, “R$”)
Next match
Next iEnd Sub
Sub APAGAR_BALOES()
Dim shp As Shape
For Each shp In ActiveSheet.Shapes
If shp.AutoShapeType = msoShapeRectangularCallout Then
shp.Delete
End If
Next shp
End Sub