vba控制图像透明度可能吗?

我的工作表中有一个图像,我想淡出。 要做到这一点,我试图find一种方法来设置图像透明度的不同阶段,如下所示:

Set myPicture = ActiveSheet.Pictures.Insert(pic) With myPicture .Transparency = 0.5 Application.Wait (Now + TimeValue("00:00:01")) .Transparency = 0.3 Application.Wait (Now + TimeValue("00:00:01")) .Transparency = 0.1 Application.Wait (Now + TimeValue("00:00:01")) .Delete End With 

目前我得到一个对象不支持的错误消息,这导致我相信这可能是不可能的。

如果可能的话,请somoene告诉我如何做到这一点? 谢谢

我花了很长时间才得到这个工作(直到我尝试了DoEvents

 Sub FadeInFadeOut() Dim r As Range Set r = Selection ActiveSheet.Shapes("Rectangle 1").Select Selection.ShapeRange.Fill.Transparency = 1 For i = 1 To 100 Selection.ShapeRange.Fill.Transparency = 1 - i / 100 DoEvents Next For i = 1 To 100 Selection.ShapeRange.Fill.Transparency = i / 100 DoEvents Next r.Select End Sub 

它在我放在工作表上的自选graphics上工作。

注意:

您必须调整100以调整淡入/淡出速度。

编辑#1:

以下是一些垃圾代码(基于logging器),用于在工作表上放置自选graphics并填充图片:

 Sub PicturePlacer() Dim sh As Shape ActiveSheet.Shapes.AddShape(msoShapeRectangle, 312.75, 176.25, 266.25, 129.75). _ Select Selection.Name = "Sargon" Application.CommandBars("AutoShapes").Visible = False Range("G4").Select ActiveCell.FormulaR1C1 = "123" Range("G5").Select ActiveSheet.Shapes("Sargon").Select Selection.ShapeRange.Fill.Transparency = 0.56 Selection.ShapeRange.Line.Weight = 0.75 Selection.ShapeRange.Line.DashStyle = msoLineSolid Selection.ShapeRange.Line.Style = msoLineSingle Selection.ShapeRange.Line.Transparency = 0# Selection.ShapeRange.Line.Visible = msoTrue Selection.ShapeRange.Line.ForeColor.SchemeColor = 64 Selection.ShapeRange.Line.BackColor.RGB = RGB(255, 255, 255) Selection.ShapeRange.Fill.Visible = msoTrue Selection.ShapeRange.Fill.ForeColor.RGB = RGB(255, 255, 255) Selection.ShapeRange.Fill.BackColor.RGB = RGB(255, 255, 255) Selection.ShapeRange.Fill.UserPicture "C:\Users\garys\Pictures\babies.jpeg" End Sub 

请记住命名该形状,并在引用该形状的所有代码中使用该名称。