gpt4 book ai didi

excel - VBA从填充形状中删除图像

转载 作者:行者123 更新时间:2023-12-03 07:50:25 27 4
gpt4 key购买 nike

我成功地用图像填充了形状。不过,我会循环浏览几张图像,为每个护林员创建一份报告。因此,创建报告后,我需要删除该图像并用另一张图像填充形状。我已经尝试了几种方法,但没有成功删除以前的图像。加载第一个图像后,即使尝试循环并用另一个图像再次填充形状也不起作用。一旦第一张图像进入,它就会保留下来。我什至尝试加载一个只是白色 block 的图像。那也行不通。请帮我再次删除此内容

enter image description here

Sub rInsertAndResizePicture()
Dim PicturePath As String
Dim PictureName As String
Dim WhiteFill As String
Dim TargetCell As Range
Dim Pic As Object
Dim TargetShape As Shape
Dim MaxWidth As Double
Dim MaxHeight As Double
Dim ShapeWidth As Single
Dim ShapeHeight As Single
Dim shp As Shape
Dim imagePath As String, whitePath As String
Dim rngImage As Picture



' Specify the name of the shape
On Error Resume Next
Set TargetShape = rRep.Shapes("RangerImageSize")
On Error GoTo 0


' Set the path and file name
PicturePath = rSys.Range("Z2").Value
PictureName = rSys.Range("Z3").Value '"Joel Somseb Torra RR.jpg"
WhiteFill = "white-600X300.png"
imagePath = PicturePath & PictureName
whitePath = PicturePath & WhiteFill


' If the shape exists, add the image to it
If Not TargetShape Is Nothing Then
On Error Resume Next
TargetShape.Fill.UserPicture whitePath

' sRep.Pictures("rngImage").Delete
' Check if the shape contains an image
' If TargetShape.Type = msoAutoShape Then
' ' Delete the image from the shape
' TargetShape.Fill.ForeColor.RGB = RGB(255, 255, 255)
' End If

On Error GoTo 0

If Dir(imagePath) <> "" Then
Set rngImage = rRep.Pictures.Insert(imagePath)
' Set rngImage = imagePath
' Name the image as "rngImage"
rngImage.Name = "rngImage"
TargetShape.Fill.UserPicture imagePath

Else
TargetShape.Fill.UserPicture whitePath
' TargetShape.Fill.ForeColor.RGB = RGB(255, 255, 255)
End If
End If

End Sub

最佳答案

如果你想删除图片,你必须应用Fill.Solid方法。

类似这样的事情

    TargetShape.Fill.Solid

关于excel - VBA从填充形状中删除图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/77301872/

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