【发布时间】:2012-03-03 04:03:18
【问题描述】:
我正在尝试将 Excel 图表复制到 Powerpoint 中的特定占位符。我使用以下代码命名了占位符
Sub NameShape()
Dim Name$
On Error GoTo AbortNameShape
If ActiveWindow.Selection.ShapeRange.Count = 0 Then
MsgBox "No Shapes Selected"
Exit Sub
End If
Name$ = ActiveWindow.Selection.ShapeRange(1).Name
Name$ = InputBox$("Give this shape a name", "Shape Name", Name$)
If Name$ <> "" Then
ActiveWindow.Selection.ShapeRange(1).Name = Name$
End If
Exit Sub
AbortNameShape:
MsgBox Err.Description
End Sub
在 Excel 中我做到了这一点:
Sub CreateNewReport()
Dim pptApp As PowerPoint.Application
Dim pptPres As PowerPoint.Presentation
Dim pptSlide As PowerPoint.Slide
Dim pptShape As PowerPoint.Shape
Dim w!, h!, t!, l!
Dim Chart As Chart
Set pptApp = CreateObject("PowerPoint.Application")
pptApp.Visible = msoTrue
Set pptPres = pptApp.Presentations.Open("C:\Users\...\Report.pptm")
Set Chart = Worksheets("Analysts").ChartObjects("Chart 2")
Set PPSlide = pptPres.Slides(4)
'PPSlide.Shapes("Analyst.Forecasts").Copy
Set pptShape = pptPres.Slides(4).Shapes(4)
With pptShape
w = .Width
h = .Height
l = .Left
t = .Top
End With
pptShape.Parent.Paste
With Selection
.Width = w
.Height = h
.Left = l
.Top = t
End With
ppt.Shape.Delete
End Sub
有人知道如何从这里拿走吗?我不太清楚如何定义要复制的图表以及如何在 Powerpoint 中粘贴和替换 shep。理想情况下我想用图表的元文件替换它,但图片也可以。
非常感谢您的帮助!
【问题讨论】:
标签: excel vba powerpoint