vba excel-2007格式的vb代码->重新着色->设置透明色

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1195162/
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 10:38:36  来源:igfitidea点击:

vb code for excel-2007 format->recolor->set transparent color

excel-vbaexcel-2007excel-2003vbaexcel

提问by

hi can you show a vb code for excel-2007 format->recolor->set transparent color on an a image inserted...

嗨,你能显示excel-2007格式的vb代码->重新着色->在插入的图像上设置透明颜色...

by the way, forgot to mention that excel-2007 record macro does not record this stuff otherwise i would not ask it here... :)

顺便说一句,忘了提到 excel-2007 记录宏不记录这些东西,否则我不会在这里问它... :)

采纳答案by RBarryYoung

OK, here is a Macro that I wrote in Excel 2007 that works:

好的,这是我在 Excel 2007 中编写的一个有效的宏:

Sub Macro3()
    Dim NewSheet As Worksheet, oldws As Worksheet
    Set oldws = ActiveWorkbook.ActiveSheet

    Dim i As Integer, obj As Shape
    Dim picFmt As PictureFormat

    Set NewSheet = Worksheets.Add
    NewSheet.Range("A1").Value = oldws.Name
    i = 3
    NewSheet.Range("A2").Value = "Name"
    NewSheet.Range("B2").Value = "Link Type"
    For Each obj In oldws.Shapes
        NewSheet.Cells(i, 1).Value = obj.Name
        NewSheet.Cells(i, 2) = obj.Type
        Set picFmt = obj.PictureFormat
        With picFmt
            NewSheet.Cells(i, 3) = .TransparencyColor
            'set Black as the Transparent color'
            .TransparencyColor = RGB(0, 0, 0)
        End With
        i = i + 1
    Next
End Sub

回答by Gary McGill

I recorded a macro in Excel 2003, and this is what I got:

我在 Excel 2003 中录制了一个宏,这就是我得到的:

Selection.ShapeRange.PictureFormat.TransparentBackground = msoTrue
Selection.ShapeRange.PictureFormat.TransparencyColor = RGB(5, 95, 209)
Selection.ShapeRange.Fill.Visible = msoFalse

I think this will work in Excel 2007 also, since everything tends to be forwards-compatible.

我认为这也适用于 Excel 2007,因为一切都倾向于向前兼容。