Macro to add text box to chart

rdw72777

Well-known Member
Joined
Apr 5, 2005
Messages
723
Howdy all,

So I'm knee-deep in some code where I'm trying to update a chart title with data and have multiple fonts in the chart title, so I'm adding a textbox and using that method

The code below seems to be doing what I want, but when I get to the last line (actually adding the textbox), it bombs out saying "Runtime error -2147417848 (80010108) Method 'add" of object "textboxes' failed.

Any thoughts on why I can't add this text box to this chart?

Code:
Set cht = ActiveChart
    
        ' Add a blank title
        cht.HasTitle = True
        Set chtT = cht.ChartTitle
        chtT.Text = vbLf
                
        'Set chart title variables
        ChartTitleLine1 = myLine1
        If z = 3 Then
            ChartTitleLine2 = "PTS Actual/Projected FTE Utilisation"
        Else
            ChartTitleLine2 = "PTS Actual/Projected FTE Utilisation by Asset"
        End If
        
        ChartTitleLine3 = Range("message18M").Value
                
        LenTitleLine1 = Len(ChartTitleLine1)
        LenTitleLine2 = Len(ChartTitleLine2)
        LenTitleLine3 = Len(ChartTitleLine3)
               
        'Remove existing textboxes on chart tabs
        If cht.TextBoxes.Count > 0 Then
            cht.TextBoxes.Delete
        End If
    
    
        ' Add and format textbox
        Set txtB = cht.TextBoxes.Add(chtT.Left + 50, chtT.Top, 100, 50)
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.

Forum statistics

Threads
1,224,603
Messages
6,179,849
Members
452,948
Latest member
UsmanAli786

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top