我有一个报告,我必须每周更新它。我更新的信息是从Excel枢轴表(从Excel复制并直接粘贴到PowerPoint上)生成的一组图像。今天我可以这样做:
Set objPPT = CreateObject("PowerPoint.Application")
objPPT.Visible = True
Set PPTPrez =
objPPT.Presentations.Open("\\network_folder\presentation.pptm")
Set pSlide = PPTPrez.Slides(2)
If pSlide.Shapes.Count <> 0 Then
ActiveWorkbook.Sheets("Pivot1").Range("A8:Z18").CopyPicture
pSlide.Shapes.Paste
EndIf
它完美无缺..。但我需要更多的控制和精确..。我需要选择幻灯片上的当前图像,删除它并粘贴在同一位置的新图片.有些幻灯片有3张或更多的图片..。我不知道如何正确地告诉VBA什么是什么,并选择枢轴表与正确的信息,该图像.我甚至不知道这是否可能..。但是我尝试过的另一个解决方案是如何指定幻灯片上图像的位置和尺寸.我可以在更新之前删除所有图像..。在这个场景中,如何指定尺寸和位置?
谢谢!
对不起,我的英语不好。
发布于 2018-11-22 18:01:14
此示例(基于您的代码)可能指向正确的方向。您需要知道powerpoint的形状名称(您可以通过VBA或丝带家庭-选择窗格获得。
Option Explicit
Public Sub UpdateShapes()
Dim vPowerPoint As PowerPoint.Application
Dim vPresentation As Presentation
Dim vSlide As Slide
Dim vShapeName As String
Dim vShape, vNewShape
Set vPowerPoint = New PowerPoint.Application
vPowerPoint.Visible = True
' Open the powerpoint presentation
Set vPresentation = vPowerPoint.Presentations.Open("\\network_folder\presentation.pptm")
' Set slide to be worked on
Set vSlide = vPresentation.Slides(2)
' Set shape to (for this example) "Picture 3"
vShapeName = "Picture 3"
Set vShape = vSlide.Shapes(vShapeName)
' Copy and paste new shape (picture) of range specified
ThisWorkbook.Sheets("Sheet1").Range("A6:B9").CopyPicture
Set vNewShape = vSlide.Shapes.Paste
' Align size and position of new shape to that of old shape
With vNewShape
.Width = vShape.Width
.Height = vShape.Height
.Left = vShape.Left
.Top = vShape.Top
End With
' Delete original shape, rename new shape to original so code works next replace cycle
vSlide.Shapes(vShapeName).Delete
vNewShape.Name = vShapeName
End Sub
https://stackoverflow.com/questions/53432768
复制相似问题