gpt4 book ai didi

excel - 如何更改 Powerpoint 形状的图像?

转载 作者:行者123 更新时间:2023-12-04 22:27:14 24 4
gpt4 key购买 nike

这是我的 PowerPoint 文件:
https://www.dropbox.com/s/7my3ubmnv7rxv8y/temp.pptx?dl=0

这是我更改形状图像的代码:

Dim presentation As Object
Set ppt = CreateObject("PowerPoint.Application")
Set presentation = ppt.Presentations.Open2007("D:\2018\temp.pptx", MsoTriState.msoFalse, MsoTriState.msoFalse, MsoTriState.msoTrue)
Dim oSlide As Object
Set oSlide = presentation.Slides(1)
oSlide.Shapes("Picture").Fill.UserPicture ("C:\Users\Public\Pictures\Sample Pictures\Chrysanthemum.jpg")

如何更改 Shape 对象的图像?

最佳答案

您要做的是创建一个填充,这不起作用,因为所讨论的形状是一张图片。您可以在 PowerPoint 中自己尝试一下。为图片设置填充无效,因为原始图像仍然可见。这就是为什么你看不到结果。
你不能改变图片本身,你必须删除它,然后替换。因此,您可以修改代码的必要部分,如下所示:

Set shp = oSlide.Shapes("Picture")
'Capture properties of the existing picture such as location and size
With shp
t = .Top
l = .Left
h = .Height
w = .Width
End With

shp.Delete 'Delete old shape

Set shp = oSlide.Shapes.AddPicture("C:\Users\Public\Pictures\Sample Pictures\Chrysanthemum.jpg", msoFalse, msoTrue, l, t, w, h)

shp.Name = "Picture"
shp.ScaleHeight Factor:=1, RelativeToOriginalSize:=msoTrue
shp.ScaleWidth Factor:=1, RelativeToOriginalSize:=msoTrue

当然,您可以将初始形状设为矩形(或其他绘图对象),然后 填写它与一张图片。在这种情况下,您可以随时更改 填写以及用于它的图片,如下所示:

Dim link as String 'set this to the address of the picture you want to use to fill
oSlide.Shapes(shp).Fill.UserPicture(link)

但如果原始形状是图片本身,通常不能用另一张图片填充它。

关于excel - 如何更改 Powerpoint 形状的图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56686443/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com