vba 更改图像形状的图像

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14503054/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 19:19:33  来源:igfitidea点击:

Change the image of an image shape

vbapowerpointpowerpoint-vba

提问by Christopher

I want to be able to change the image of an image shape by clicking on an button in my userform.

我希望能够通过单击用户表单中的按钮来更改图像形状的图像。

In the internet I found the function UserPicture, but the image simply stays the same.

在互联网上我找到了函数UserPicture,但图像只是保持不变。

Private Sub ChangeImage_Click()
    ActivePresentation.Slides("Slide1").Shapes("SolutionA_Image").Visible = True

    ActivePresentation.Slides("Slide1").Shapes("SolutionA_Image").Fill.UserPicture ("D:\User\Desktop\SolutionWrong.jpg")
End Sub

Private Sub HideImage_Click()
    ActivePresentation.Slides("Slide1").Shapes("SolutionA_Image").Visible = False
End Sub

When I click on the HideImagebutton, the shape becomes invisible, so my selection of the shape appears to be right.

当我单击HideImage按钮时,形状变得不可见,因此我对形状的选择似乎是正确的。

I also tried

我也试过

ActivePresentation.Slides("Slide1").Shapes("SolutionA_Image").Fill.UserPicture "D:\User\SolutionWrong.jpg"

but this does not work either

但这也不起作用

Edit
Of course I checked the path to the new image, it's correct.

编辑
当然我检查了新图像的路径,它是正确的。

采纳答案by Christopher

Siddharth Rout found the solution

Siddharth Rout 找到了解决方案

I created the image by selecting picturefrom the insertmenu, but it have to be created via Insert=> Rectangular shape(no border). Now it can easily be accessed by using ActivePresentation.Slides("Slide1").Shapes("SolutionA_Image").Fill.UserPicture ("D:\User\SolutionWrong.jpg")

我通过pictureinsert菜单中选择来创建图像,但它必须通过Insert=> Rectangular shape(无边框)创建。现在它可以通过使用轻松访问ActivePresentation.Slides("Slide1").Shapes("SolutionA_Image").Fill.UserPicture ("D:\User\SolutionWrong.jpg")