【发布时间】:2021-10-24 18:49:13
【问题描述】:
我正在尝试使用 VBA 在 ppt 中粘贴图表。我从 Excel 中的一个范围内复制了一个图表并将其粘贴到 ppt 中。我的问题是调整大小和排列,使其适合 ppt 模板幻灯片。我想在每张幻灯片上粘贴一张图片。到目前为止,我有:
Dim PPT As Object
Set PPT = CreateObject("Powerpoint.application")
PPT.Visible = True
PPT.Presentations.Open Filename:="x:\xx.pptx"
Const START_LEFT_POS = 100
Const START_TOP_POS = 5
Const gap As Long = 5
Dim LeftPos As Long
LeftPos = START_LEFT_POS
Dim TopPos As Long
TopPos = START_TOP_POS
Dim NextSlideIndex As Long
NextSlideIndex = 2
PPT.ActiveWindow.View.gotoslide NextSlideIndex
Dim range_1 As Range
Dim AllRanges(1 To 5) As Variant
Sheets("Charts").Activate
AllRanges(1) = "J132:Q149": AllRanges(2) = "J150:Q168": AllRanges(3) = "J169:Q183": AllRanges(4) = "S139:AC149": AllRanges(5) = "V166:Y180"
Dim ChrtIndex As Long
For ChrtIndex = 1 To 5
Set range_1 = Range(AllRanges(ChrtIndex))
range_1.CopyPicture appearance:=xlScreen, Format:=xlPicture
PPT.ActiveWindow.View.PasteSpecial DataType:=2
With PPT.ActiveWindow.View.slide
With .Shapes(ChrtIndex)
.Left = LeftPos
.Width = 160
.Height = 155
End With
End With
PPT.ActiveWindow.View.gotoslide NextSlideIndex + 1
Next ChrtIndex
谢谢!
【问题讨论】:
-
您在这里要解决的具体问题是什么?不清楚。
-
我的问题是,当我粘贴图片并排列它们时,它们不会移动。但是,模板幻灯片中的文本框会移动。我需要在我的代码中激活图片然后对其进行排列。我希望这是有道理的?
标签: excel vba powerpoint