Change the background color of a textbox that is positioned in a chart

rjh

New Member
Joined
Jun 18, 2010
Messages
29
Hi Guys,
I have been chasing my tail on this one.

I have a chart and I want to place a "label" on it using a textbox. I need to make the background of the textbox white and the text black.

here is the code I have.

Code:
Sub Sticker()

With ActiveChart.Shapes.AddTextbox(msoTextOrientationHorizontal, 370, 300, 300, 105)
            With .TextFrame
                .Characters.Text = "   OVEN S/N:  834247R                                      FURNACE #:  J-1" _
                     & Chr(13) & "   TEMPERATURE RANGE:  1340F-1360F        CONTROL SET POINT: 1350F" _
                     & Chr(13) & "   RECORDER READING:                                CONTROL READING:" _
                     & Chr(13) & "   THERMOCOUPLES: 20" _
                     & Chr(13) & "   SURVEY CONDUCTED BY:____________  DATE: ___________" _
                     & Chr(13) & "   METER NUMBER:  452239                          RECALL DATE: 04/14/2019" _
                     & Chr(13) & "   RECORDER S/N:"

                .MarginBottom = 0: .MarginLeft = 0
                .MarginRight = 0: .MarginTop = 0
                .BackColor.RGB = RGB(255, 255, 255) '   <----------------THIS LINE THE PROBLEM!
                .HorizontalAlignment = xlHAlignLeft
                .VerticalAlignment = xlVAlignCenter

                With .Characters.Font
                    .Name = "Times New Roman": .Size = 8
                    .FontStyle = "Bold": .ColorIndex = 1

                End With

            End With
            ' border
            With .Line
                .Style = msoLineSingle
                .Transparency = 0
                .Visible = msoTrue

            End With

        End With

End Sub

Thanks
Rick
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Re: Change the background color of a textbox that is posistioned in a chart

Hi Rick

I would set the text colour in the TextFrame.Characters, like you did, but the shape colour in the Shape.Fill, like in this example.

Try:

Code:
Sub Sticker()

ActiveChart.DrawingObjects.Delete
With ActiveChart.Shapes.AddTextbox(msoTextOrientationHorizontal, 370, 300, 300, 105)
            With .TextFrame
                .Characters.Text = "   OVEN S/N:  834247R                                      FURNACE #:  J-1" _
                     & Chr(13) & "   TEMPERATURE RANGE:  1340F-1360F        CONTROL SET POINT: 1350F" _
                     & Chr(13) & "   RECORDER READING:                                CONTROL READING:" _
                     & Chr(13) & "   THERMOCOUPLES: 20" _
                     & Chr(13) & "   SURVEY CONDUCTED BY:____________  DATE: ___________" _
                     & Chr(13) & "   METER NUMBER:  452239                          RECALL DATE: 04/14/2019" _
                     & Chr(13) & "   RECORDER S/N:"

                .MarginBottom = 0: .MarginLeft = 0
                .MarginRight = 0: .MarginTop = 0
                .HorizontalAlignment = xlHAlignLeft
                .VerticalAlignment = xlVAlignCenter

                With .Characters.Font
                    .Name = "Times New Roman": .Size = 8
                    .FontStyle = "Bold": .Color = vbRed

                End With

            End With
            
            .Fill.ForeColor.RGB = vbGreen
            
            ' border
            With .Line
                .Style = msoLineSingle
                .Transparency = 0
                .Visible = msoTrue

            End With

        End With

End Sub
 
  • Like
Reactions: rjh
Upvote 0

Forum statistics

Threads
1,215,047
Messages
6,122,858
Members
449,096
Latest member
Erald

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