CommandBarButton.Picture 属性 (Office)

获取或设置一个 IPictureDisp 对象,该对象表示 CommandBarButton 对象的图像。 读/写。

注意

某些 Microsoft Office 应用程序中对 CommandBars 的使用已由 Microsoft Office Fluent 用户界面的新功能区组件取代。 有关详细信息,请参阅 Office Fluent 功能区概述

语法

表达式图片

表达 一个代表 CommandBarButton 对象的变量。

备注

更改按钮上的图像时,还需要使用 Mask 属性设置掩码图像。 屏蔽图像决定按钮图像透明的部分。 通常在设置了 CommandBarButton 对象的图片后设置屏蔽。

注意

无法更改 Visual Basic 编辑器中标准工具栏上的“查看 Microsoft应用程序”和“插入”按钮的图像。

示例

下面的示例设置代码返回的第一个 CommandBarButton 的图像和屏蔽。 要使本示例正常工作,请创建一个屏蔽图像和一个按钮图像,并用这些图像的路径替换示例中的路径。

Sub ChangeButtonImage() 
    Dim picPicture As IPictureDisp 
    Dim picMask As IPictureDisp 
 
    Set picPicture = stdole.StdFunctions.LoadPicture( _ 
        "c:\images\picture.bmp") 
    Set picMask = stdole.StdFunctions.LoadPicture( _ 
        "c:\images\mask.bmp") 
 
    'Reference the first button on the first command bar 
    'using a With...End With block. 
    With Application.CommandBars.FindControl(msoControlButton) 
        'Change the button image. 
        .Picture = picPicture 
 
        'Use the second image to define the area of the 
        'button that should be transparent. 
        .Mask = picMask 
    End With 
End Sub

下面的示例获取代码返回的第一个 CommandBarButton 的图像和屏蔽,并将它们输出到文件。 要使本示例正常工作,请指定输出文件的路径。

Sub GetButtonImageAndMask() 
    Dim picPicture As IPictureDisp 
    Dim picMask As IPictureDisp 
 
    With Application.CommandBars.FindControl(msoControlButton) 
        'Get the button image and mask of this CommandBarButton object. 
        Set picPicture = .Picture 
        Set picMask = .Mask 
    End With 
 
    'Save the button image and mask in a folder. 
    stdole.SavePicture picPicture, "c:\image.bmp" 
    stdole.SavePicture picMask, "c:\mask.bmp" 
End Sub 

另请参阅

支持和反馈

有关于 Office VBA 或本文档的疑问或反馈? 请参阅 Office VBA 支持和反馈,获取有关如何接收支持和提供反馈的指南。