在Excel中使用VBA设置图像透明度

3

是否有一种使用VBA脚本对图像应用一些透明效果的方法?我已经录制了一个“宏”,但艺术效果并没有被记录下来。我已经找到了如何为形状创建透明度,但对于图像还没有找到。

2个回答

2
这需要几个步骤:
  1. 在工作表上放置一个自动形状(如矩形)
  2. 使用:.ShapeRange.Fill.UserPicture 将您的实际图片嵌入矩形中
  3. 使用:.ShapeRange.Fill.Transparency 调整透明度

0
您可以使用以下代码:删除背景图像并使用工具图片格式,在Excel中设置透明颜色。
Sub RemoveBackground()
  Dim selectedPicture As Picture
  Set selectedPicture = ActiveSheet.Pictures("Picture 3")
' Set the transparent color of the picture
  With selectedPicture.ShapeRange.PictureFormat
    .TransparentBackground = True
    .TransparencyColor = RGB(255, 255, 255)
  End With 
End Sub

  Sub RemoveShapes()
  ' Select the image you want to remove the background from
  Dim selectedImage As Shape
  Set selectedImage = ActiveSheet.Shapes("Image1")     ' Set the transparent color of the image 

  With selectedImage.PictureFormat
    .TransparentBackground = msoTrue
    .TransparencyColor = RGB(255, 255, 255)
  End With
End Sub

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接