vba 名称框中的 Excel 图表名称
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8239123/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Excel Chart names in Name Box
提问by CuriousCase
I am creatin multiple charts on a single sheet. Lets say I have a sheet "Sheet 1" and on this sheet I am creating 10 charts with name from "chart 1" to "Chart 10". But the problem is when I click the name box,list of all the charts is not available in that name box. Can any one help me out how to do that through simple excel or excel VBA.
我在一张纸上创建多个图表。假设我有一个工作表“工作表 1”,在这张工作表上我创建了 10 个图表,名称从“图表 1”到“图表 10”。但问题是当我单击名称框时,该名称框中没有所有图表的列表。任何人都可以通过简单的 excel 或 excel VBA 帮助我了解如何做到这一点。
回答by brettdj
Update: I don't believe anything other than range names or the currently selected object is available in the "name box". The only alteration I have ever seen made to the name box is a width increase
更新:除了范围名称或当前选定的对象在“名称框”中可用之外,我不相信任何其他内容。我见过对名称框所做的唯一更改是宽度增加
In Xl2010 you can see all the charts using the Selection Pane Home .... Editing .... Find & Select .... Selection Pane
在 Xl2010 中,您可以使用选择窗格主页 .... 编辑 .... 查找和选择 .... 选择窗格查看所有图表
OriginalSomething like this would give you the list
原来这样的东西会给你列表
Did you want the ability to select a chart from the list and activate it, or just the list itself?
您是否希望能够从列表中选择图表并激活它,或者只是列表本身?
Sub GetCharts()
Dim chr As ChartObject
Dim strOut As String
For Each chr In Sheets(1).ChartObjects
strOut = strOut & chr.Name & vbNewLine
Next
If Len(strOut) > 0 Then
MsgBox "Chart Names are:" & vbNewLine & strOut
Else
MsgBox "No charts", vbCritical
End If
End Sub
回答by Tony Dallimore
The macro below outputs more information about the charts in a workbook and a worksheet than brettdj's. The idea is to give you a fuller indication of the information that is available and how you access it.
下面的宏比 brettdj 输出更多关于工作簿和工作表中图表的信息。这样做的目的是让您更全面地了解可用信息以及您如何访问这些信息。
However, I do not understand what you want to appear in the Name Box.
但是,我不明白您想在名称框中显示什么。
Sub Test1()
Dim InxCO As Integer
Dim InxWS As Integer
For InxWS = 1 To Worksheets.Count
With Sheets(InxWS)
Debug.Print "Worksheet: " & .Name
Debug.Print " " & .ChartObjects.Count & " charts"
For InxCO = 1 To .ChartObjects.Count
With .ChartObjects(InxCO)
Debug.Print " Chart: " & .Name
Debug.Print " Location: " & .TopLeftCell.Address & " to " & _
.BottomRightCell.Address
If .Chart.HasTitle Then
Debug.Print " Title: " & .Chart.ChartTitle.Text
Else
Debug.Print " Untitled"
End If
End With
Next
End With
Next
End Sub
回答by SkipVought
If you have Excel 2007+, there is a Selection and Visibility windowthat you can activate.
如果您有 Excel 2007+,则可以激活一个选择和可见性窗口。
To see this,
看到这个,
1) insert ANY shape on your sheet
2) **Format > Arrange > Selection Pane**
You can, at this point, right-click the Selection Pane icon and add it to your QAT. Using the icon on your QAT, means that the Selection and Visibility windowcan be activated any time, with or without shapes on a sheet.
此时,您可以右键单击“选择窗格”图标并将其添加到您的 QAT。使用 QAT 上的图标意味着可以随时激活“选择和可见性”窗口,无论工作表上有没有形状。