excel - 使用 VBA 编辑图例
问题描述
我将图表(我在 excel 中准备的带有图例的图表)从 excel 复制到 .ppt(下面的代码)。如何更改/编辑 legend.Top 和 legend.size?
我的代码不起作用...
Sub pptfromexcel()
Dim pptapp As PowerPoint.Application
Dim pptppt As PowerPoint.Presentation
Dim pptsld As PowerPoint.Slide
Dim shp As Object
Set chart1 = ActiveSheet.ChartObjects("Chart 1")
'Dane do wykresów
Set d5 = Sheets("Wykresy").Range("Q32:S40")
Set d6 = Sheets("Wykresy").Range("Q47:S51")
Set v1PK = Sheets("Wykresy").Range("G7:G7")
Set v1PM = Sheets("Wykresy").Range("G8:G8")
Set pptapp = New PowerPoint.Application
Set pptppt = pptapp.Presentations.Open("C:\Users\Desktop\ppt.pptx")
pptapp.Visible = True
pptapp.Activate
Set pptsld2 = pptppt.Slides(2)
chart1.Copy
Set chart1a = pptsld2.Shapes.PasteSpecial
With chart1a
.Height = 132
.Width = 157
.Left = 26.1
.Top = 120
.haslegend=true
.legend.size = 12
.legend.top = 150
End With
End Sub
解决方案
您设置的前四个属性是所有形状的通用属性。图例属性特定于图表。必须发生的第一件事是将其粘贴为 Excel 对象。如果是这种情况,您的形状上有一个 Chart 属性,您可以这样做:
With chart1a
.Height = 132
.Width = 157
.Left = 26.1
.Top = 120
.Chart.HasLegend = True
.Chart.Legend.Size = 12
.Chart.Legend.Top = 150
End With
推荐阅读
- linux - linux机器上的最大登录会话数
- r - colSums 问题 - 选择了未定义的列
- python - 在python中从excel中读取数据并发出http请求
- android - 如何在不跳过事件的情况下监听 ViewModel 中的一系列修改?
- node.js - 使用贝宝和自动提款付款保留付款
- ios - 如何知道我的 iPhone 与哪个蓝牙 5 功能兼容?
- apache-spark - 如何在一些停用词后过滤文本?
- xamarin.forms - 移动底部的按钮并为编辑器提供更多空间
- c - C文件中的结构列表
- javascript - jQuery - AJAX - 通过 FormData 上传文件不起作用