簡體   English   中英

如何更改Powerpoint形狀的圖像?

[英]How to change image of a Powerpoint shape?

這是我的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)

但是,如果原始形狀是圖片本身,則通常無法用其他圖片填充它。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM