Gets or sets an IPictureDisp object representing the image of a CommandBarButton object. Read/write.

Note
The use of CommandBars in some Microsoft Office applications has been superseded by the new Ribbon user interface. For more information, search help for the keyword "Ribbon."

Syntax

expression.Picture

expression A variable that represents a CommandBarButton object.

Remarks

When you change the image on a button, you will also want to use the Mask property to set a mask image. The mask image determines which parts of the button image are transparent. Always set the mask after you have set the picture for a CommandBarButton object.and Insert buttons on the Standardtoolbar in the Visual Basic Editor cannot be changed.

Note
The images for the View Microsoft Application Item

Example

The following example sets the image and mask of the first CommandBarButton that the code returns. To make this work, create a mask image and a button image and substitute the paths in the sample with the paths to your images.

Visual Basic for Applications
Sub ChangeButtonImage() Dim picPicture As IPictureDisp Dim picMask As IPictureDisp Set picPicture = stdole.StdFunctions.LoadPicture( _ "c:\images\picture.png") Set picMask = stdole.StdFunctions.LoadPicture( _ "c:\images\mask.png") '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

The following example gets the image and mask of the first CommandBarButton that the code returns and outputs each of them to a file. To make this work, specify a path for the output files.

Visual Basic for Applications
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.png" stdole.SavePicture picMask, "c:\mask.png" End Sub 
ofv Picture Picture Property

See also: