Applying Texture Settings to Shapes in Office 2010

Office Quick Note banner

Working Programmatically with Shapes in Office 2010: Learn how to work with the FillFormat class' texture settings in Microsoft PowerPoint 2010.

Applies to: Excel 2010 | Office 2007 | Office 2010 | PowerPoint 2010 | Word 2010

In this article
Add a Standard Module to a PowerPoint Presentation
Add the Code to the Visual Basic Editor
Test the Solution
Next Steps

Published:   June 2011

Provided by:    Frank Rice, Microsoft Corporation

A shape can have a solid, gradient, texture, pattern, picture, or semi-transparent fill. The FillFormat object enables you to work with fill formatting for a shape. In this topic, you programmatically add a shape to a Microsoft PowerPoint 2010 presentation. You then manipulate the texture and rotation properties of the shape. To complete this task, you must do the following:

  • Add a Standard Module to a PowerPoint Presentation

  • Add the Code to the Visual Basic Editor

  • Test the Solution

Add a Standard Module to a PowerPoint Presentation

In this task, you open a PowerPoint 2010 presentation, open the Visual Basic Editor, and then insert a standard module.

To add a standard module to a PowerPoint presentation

  1. Start PowerPoint 2010.

  2. On the Developer tab, click Visual Basic. This opens the Visual Basic Editor.

    Note

    If you do not see the Developer tab in PowerPoint 2010, click the File tab, and then click Options. In the categories pane, click Popular, select Show Developer tab in the Ribbon, and then click OK.

  3. On the Insert menu, click Module. This adds Module1 to the Projects pane on the left side of the Visual Basic Editor.

Add the Code to the Visual Basic Editor

In this task, you add programming code to the Visual Basic Editor.

To add code to the Visual Basic Editor

  1. In the Projects pane, click Module1.

  2. Paste or type the following Microsoft Visual Basic for Applications (VBA) code into the module window.

    Sub TextureStyleDemo()
        ' Create a new slide with a simple table:
        Dim sld As Slide
        Set sld = ActivePresentation.Slides.Add(2, ppLayoutBlank)
        sld.Select
    
        Dim shp As Shape
        Set shp = sld.Shapes.AddShape(msoShapeSnipRoundRectangle, 50, 50, 400, 400)
        shp.Fill.PresetTextured msoTextureFishFossil
    
        With shp.Fill
            ' Set the alignment. There are other options, as well:
            .TextureAlignment = msoTextureTop
            .TextureAlignment = msoTextureBottom
            .TextureAlignment = msoTextureLeft
            .TextureAlignment = msoTextureRight
    
            ' TextureHorizontalScale is a percentage, as a fraction.
            ' This corresponds to the Scale X setting in the user interface:
            .TextureHorizontalScale = 1
            .TextureHorizontalScale = 0.75
            .TextureHorizontalScale = 0.5
            .TextureHorizontalScale = 0.25
            .TextureHorizontalScale = 1
    
            ' TextureVerticalScale is a percentage, as a fraction:
            ' This corresponds to the Scale Y setting in the user interface:
            .TextureVerticalScale = 1
            .TextureVerticalScale = 0.75
            .TextureVerticalScale = 0.5
            .TextureVerticalScale = 0.25
            .TextureVerticalScale = 1
    
            ' TextureOffsetX is measured in points:
            .TextureOffsetX = 10
            .TextureOffsetX = 50
            .TextureOffsetX = 100
    
            ' TextureOffsetY is measured in points:
            .TextureOffsetY = 10
            .TextureOffsetY = 50
            .TextureOffsetY = 100
    
            ' If you don't tile the texture, it only appears
            ' once inside the shape. The texture
            ' then stretches to fill the entire shape.
            .TextureTile = msoFalse
    
            ' Reset the texture so that it tiles. Notice that this also
            ' resets the tiling--it now looks different than it did
            ' previously!
            .TextureTile = msoTrue
    
            ' Reset the texture:
            .PresetTextured msoTextureFishFossil
    
            ' You can determine whether the texture rotates
            ' with the shape. First, try rotating the shape
            ' without rotating the texture:
            .RotateWithObject = msoFalse
            shp.Rotation = 10
    
            ' Changing RotateWithObject immediately rotates
            ' the texture to match the existing rotation:
            .RotateWithObject = msoTrue
            shp.Rotation = 30
        End With
    End Sub
    

Test the Solution

In this task, you step through the code. The best way to see the code in action is to place the Visual Basic Editor and the PowerPoint screen side-by-side.

To step through the code

  1. Drag the Visual Basic Editor to the right side of the screen.

  2. Next, drag the PowerPoint screen to the left side of the screen and adjust both screens until you can see them clearly.

  3. Place your cursor in the TextureStyleDemo module and then press F8 to step through the code line-by-line and watch the results.

Next Steps