通过Powerpoint中的VBA操纵图表的选定成员 [英] manipulate selected members of a chart via VBA in Powerpoint

查看:273
本文介绍了通过Powerpoint中的VBA操纵图表的选定成员的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我目前正面临这个障碍:

我想通过选择将一些做法应用于powerpoint中的图表对象的成员它通过点击然后运行宏。假设它是x轴标签,但可以是任何其他标签/图例或者您可以通过菜单栏插入的任何内容。

宏不应该用于在图表中创建的简单形状。问题是,我无法获得所选对象,只有父图表。

我发现它也很奇怪,我不能通过宏选择图表中的项目而不选择父图表形状第一。关于如何获得所选对象的任何想法?

Hi,
I'm currently facing this obstacle:
I want to apply some doing to a member of a chart object in powerpoint, by selecting it via click and then running a macro. Let's say it's the x-axis-label, but could be any other label / legend or whatever you can insert via menu bar.
The macro is NOT supposed to be used for simple shapes created inside a chart. Problem is, that I can't get the selected object, only the parent chart.
I find it also odd, that I can't select items inside a chart via macro without selecting the parent chart shape first. any ideas on how to get the selected object?

谢谢!

Julian

示例:

Option Explicit
Sub test()

Dim sld As Slide
Dim crt As Shape
Dim leg As Legend
Dim xlab As AxisTitle

Set sld = ActivePresentation.Slides.Add(ActivePresentation.Slides.Count + 1, ppLayoutBlank)
sld.Select
Set crt = sld.Shapes.AddChart(xlXYScatter)

'add labels
crt.Chart.HasLegend = True
Set leg = crt.Chart.Legend
crt.Chart.Axes(1).HasTitle = True
Set xlab = crt.Chart.Axes(1).AxisTitle
crt.Chart.Axes(2).HasTitle = True
crt.Chart.HasTitle = True

'select objects in chart and check what is selected

'does not work:
leg.Select

'works, chart has to be selected first
crt.Select
leg.Select
If ActiveWindow.Selection.ShapeRange(1) Is crt Then
    Debug.Print ("it's the chart")
End If

'works, chart has to be selected first
crt.Select
xlab.Select
If ActiveWindow.Selection.ShapeRange(1) Is crt Then
    Debug.Print ("it's the chart")
End If

End Sub




推荐答案

图例代表图表。每个图表只能有一个图例
,PowerPoint 使图例和图表彼此不可分割
所以你可以尝试如下:

The legend represents in a chart. Each chart can have only one legend, and PowerPoint has made the legend and the chart integral to each other. So you can try like below:

Dim shp As Shape
Set shp = ActivePresentation.Slides(1).Shapes.AddChart(xl3DPie)

Dim cht As Chart
Set cht = shp.Chart
With cht.Legend
    ......
End With


这篇关于通过Powerpoint中的VBA操纵图表的选定成员的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆