Talvez queira alertar contra a tentativa de alteração do título dos gráficos que disponibilizou nos seus Dashboards, Scorecard, ou mesmo num gráfico dinâmico da sua aplicação MS Excel. Isso pode ser implementado com alguma codificação simples.
O exemplo abaixo mostra uma caixa de mensagem caso o usuário selecione o título do gráfico.
Divirta-se!
Private Sub Chart_Select(ByVal ElementID As Long, _ByVal Arg1 As Long, ByVal Arg2 As Long)If ElementId = xlChartTitle ThenMsgBox ".: A&A - Por favor, não altere o título do gráfico"End IfEnd Sub
E como posso inserir um título no meu gráfico?
Assim:
With Worksheets("sheet1").ChartObjects(1).ChartLet .HasTitle = TrueLet .ChartTitle.Text = "Vendas da A&A - In Any Place"End With
Então, que tal adicionar toda uma série ao seu gráfico, e não somente o título?
Sub AddSeries2Char()
Dim counter As Integer
Dim index As Integer
Dim columnPosition As Integer
Dim curveLength As Long
Dim seriesCount As Integer
Dim removeData As Boolean
Dim myChart As Chart
shForwardCurves.Activate
'On Error Resume Next
ActiveSheet.ChartObjects(1).Delete
' getting the length of the curves and number of series
Dim curveRange As Variant
Let curveRange = shForwardCurves.Range(shForwardCurves.Cells(21, 3), shForwardCurves.Cells(21, 3).End(xlToRight))
Let seriesCount = UBound(curveRange, 2)
Let curveLength = 365
Range("B2").Select
Set myChart = Charts.Add
Set myChart = myChart.Location(Where:=xlLocationAsObject, Name:="Forward Curves")
With myChart
Let .ChartType = xlLine
Let .SeriesCollection(1).XValues = "='Forward Curves'!R23C2:R" & curveLength + 23 & "C2"
Let .SeriesCollection(1).values = "='Forward Curves'!R23C3:R" & curveLength + 23 & "C3"
Let .HasTitle = True
Let .ChartTitle.Text = "Forward Curve"
' check if the data is present or not; based on that put one dummy data and after remove that
If shForwardCurves.Cells(23, 3).Value = "" Then
Let shForwardCurves.Cells(23, 3).Value = 11
Let removeData = True
End If
Let .SeriesCollection(1).Name = "='Forward Curves'!R21C3"
If removeData Then
Let removeData = False
Let shForwardCurves.Cells(23, 3).Value = ""
End If
With .Parent
Let .Top = Range("b2").Top
Let .Left = Range("b2").Left
Let .Name = "My Chart"
End With
For index = 2 To seriesCount
ActiveChart.SeriesCollection.NewSeries
Let columnPosition = index + 2
Let ActiveChart.SeriesCollection(index).values = "='Forward Curves'!R23C" & CStr(columnPosition) & ":R" & curveLength + 23 & "C" & CStr(columnPosition)
' check if the data is present or not; based on that put one dummy data and after remove that
If shForwardCurves.Cells(23, columnPosition).Value = "" Then
Let shForwardCurves.Cells(23, columnPosition).Value = 11
Let removeData = True
End If
Let ActiveChart.SeriesCollection(index).Name = "='Forward Curves'!R21C" & CStr(columnPosition)
If removeData Then
Let removeData = False
Let shForwardCurves.Cells(23, columnPosition).Value = ""
End If
Next
With .PlotArea
Let .Top = 19
Let .Height = 229
End With
End With
With shForwardCurves.Shapes("My Chart")
.ScaleWidth 1.92, msoFalse, msoScaleFromTopLeft
.ScaleHeight 1.05, msoFalse, msoScaleFromTopLeft
End With
End Sub