excel - 如何控制图像透明度?

标签 excel image vba transparency

我的工作表中有一张我想淡出的图像。
我想为图像设置不同的透明度阶段:

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
我收到一条错误消息。

object not supported

最佳答案

我花了很长时间才让它工作(直到我尝试了 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

它适用于我放置在图纸上的自选图形。

注意:

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

编辑#1:

这是一些垃圾代码(基于记录器),用于将自选图形放在一张纸上并用图片填充它:
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

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

关于excel - 如何控制图像透明度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41223436/

相关文章:

vba - 使用连续数据列中的特定条件选择范围

excel - 如何根据单元格值返回标题名称?编程语言

excel - 插入新行时将公式复制到下一行

javascript - 无法启动 "document.write();"中的功能

vba - SQLite UDF - VBA 回调

iphone - 在 Facebook 连接 iphone 上上传图像

html - 如何在 HTML5 中叠加两个图像

arrays - Excel VBA : two dimensional array with variable and time stamp

excel - SUMIF 值大于上一列中的值

excel - map 图表在 Power Map 中有效,但在 Power View map 中无效