Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Delete text boxes that are located on charts

Posted on 2011-09-18
3
Medium Priority
?
290 Views
Last Modified: 2012-05-12
Dear Experts:

Below macro places a text box (contents are named ranges) into each and every chart of the active worksheet.

The macro runs just fine.

There is one problem: I got no idea how to DELETE ONLY these text boxes that were created by running below macro and leave all other possible text boxes (data labels) or ordinary' text boxes located outside the chart alone.

I have attached a sample file with below code integrated for your convenience.

Help is much appreciated. Thank you very much in advance.

Regards, Andreas

 SampleFileTextBoxes.xlsm
Sub TextBoxes_Add_ToCharts()

'Add text box
'You can assign the result of the AddTextbox method to a Shape object variable and manipulate its Top, Left,
'Height and Width properties 
'1. Value = Left property
'2. Value = Top property
'3. Value = Width property
'4. Value = Height property


Dim chtTemp As Chart
Dim objTemp As Object
Dim x As Integer

x = 1
Do While x <= ActiveSheet.ChartObjects.Count
Set chtTemp = ActiveSheet.ChartObjects(x).Chart
Set objTemp = chtTemp.Shapes.AddTextBox(msoTextOrientationHorizontal, 285, 171, 135, 20)

objTemp.Select
Selection.Formula = "='" & chtTemp.Parent.Parent.Name & "'!Blue_Range_TextBox_" & Format(x, "00")
x = x + 1
Loop

ActiveCell.Select

End Sub

Open in new window

0
Comment
Question by:AndreasHermle
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 93

Accepted Solution

by:
Patrick Matthews earned 2000 total points
ID: 36556717
I modified your original procedure to add a fixed name to those textboxes, which then allows us to identify them for a sub that would try to delete them (also supplied here):


Sub TextBoxes_Add_ToCharts()

'Add text box
'You can assign the result of the AddTextbox method to a Shape object variable and manipulate its Top, Left,
'Height and Width properties (relative to those properties for myChtObj).
'myChtObj.Chart.Shapes.AddTextbox(msoTextOrientationHorizontal, 30.75, 11.25, 57.75, 21#)
'1. Value = Left property
'2. Value = Top property
'3. Value = Width property
'4. Value = Height property


Dim chtTemp As Chart
Dim objTemp As Object
Dim x As Integer

x = 1
Do While x <= ActiveSheet.ChartObjects.Count
Set chtTemp = ActiveSheet.ChartObjects(x).Chart
Set objTemp = chtTemp.Shapes.AddTextBox(msoTextOrientationHorizontal, 285, 171, 135, 20)
With objTemp
    .Select
    Selection.Formula = "='" & chtTemp.Parent.Parent.Name & "'!Blue_Range_TextBox_" & Format(x, "00")
    .Name = "TextBoxes_Add_ToCharts"
End With
x = x + 1
Loop

ActiveCell.Select

End Sub


Sub KillTextBoxes()
    
    Dim cht As ChartObject
    Dim shap As Shape
    Dim Counter As Long
    
    For Each cht In ActiveSheet.ChartObjects
        For Each shap In cht.Chart.Shapes
            If shap.Name = "TextBoxes_Add_ToCharts" Then
                shap.Delete
                Counter = Counter + 1
            End If
        Next
    Next
    
    If Counter Then
        msgbox "I killed " & Counter & " TextBoxes", vbInformation, "Yahtzee!"
    Else
        msgbox "No matching TextBoxes found", vbExclamation, "Wasting my time"
    End If
    
End Sub

Open in new window

0
 

Author Closing Comment

by:AndreasHermle
ID: 36556898
Hi Patrick,

you know that you are one of the best here, don't you!

Great job. Exactly what I wanted. Thank you very much for your professional help. I really, really appreciate it. This forum is just great.

Regards, Andreas
0
 
LVL 93

Expert Comment

by:Patrick Matthews
ID: 36557012
Glad to help, Andreas!
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How to get Spreadsheet Compare 2016 working with the 64 bit version of Office 2016
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question