The information in this article applies to:
SUMMARYUsing a macro, you can alter every aspect of an object: from the object's fill color, to the shape of the object itself. This article covers only a few of the changes that you can make to alter the appearance of a shape object. MORE INFORMATIONMicrosoft provides programming examples for illustration only, without warranty
either expressed or implied, including, but not limited to, the implied warranties of
merchantability and/or fitness for a particular purpose. This article assumes that you
are familiar with the programming language being demonstrated and the tools used to
create and debug procedures. Microsoft support professionals can help explain the functionality
of a particular procedure, but they will not modify these examples to provide added
functionality or construct procedures to meet your specific needs. If you have limited
programming experience, you may want to contact a Microsoft Certified Solution Provider
or the Microsoft fee-based consulting line at (800) 936-5200. For more information about
Microsoft Certified Solution Providers, please see the following page on the World Wide Web:
http://www.microsoft.com/mcsp/For more information about the support options available from Microsoft, please see the following page on the World Wide Web: http://www.microsoft.com/support/supportnet/overview/overview.asp Altering the Color of a ShapeYou can change the fill color of an object in one of two ways: by changing its color setting from the color scheme, or by altering the raw red-green-blue (RGB) values of the object directly. The following code fragment shows how to modify the color of a shape by changing the color scheme settings:
There are eight different scheme colors to choose from:
You can also reference color scheme types by their numeric value. ppBackground has the value 1, and ppAccent3 has the value 8. These values are useful if you want to quickly cycle through the various colors in a slide's color scheme. The following code fragment shows how you would implement this:
The second method of changing the color of an object is to alter the RGB values of its color. RGB stands for red-green-blue, the standard color model for displays. The following code fragment has the shape's fill color set to a color of blue:
Using the RGB color model allows you to generate 16 million different colors easily. For reference to basic color values, use this chart:
Altering the Size of a ShapeYou can change the size of an object, by modifying its Height and Width properties or by using the ScaleHeight and ScaleWidth methods.Height and Width are measured in points, sizing the object from its upper-left corner. The following code makes the shape with ZOrder of 1 as wide as the slide, and 10 points tall, but the object resizes from its upper-left corner, not from around its middle:
To resize around the center of the object, you would have to use the following code:
The preceding code performs a calculation that centers the object around its own middle. It gets the original height and width of the object and then uses that information to center it. Because the Top and Left values do not change, you can use them to derive the new Top and Left values.There is a simpler way to do this. Instead of using the Height and Width values, we use the two methods: ScaleHeight and ScaleWidth. These methods allow you to resize about the center of the object with no problem. The following code is another way to create the above effect:
Both ScaleHeight and ScaleWidth take the following parameters:
Factor: This specifies the ratio between the height of the shape after you resize it and the current or original height. For example, to make a rectangle 50 percent larger, specify 1.5 for this argument. RelativeToOriginalSize: Set this to True to scale the shape relative to its original size. Set this to False to scale it relative to its current size. You can specify True for this argument only if the specified shape is a picture or an OLE object. fScale: Optional. This determines the anchor point about which the object is scaled. Can be one of the following MsoScaleFrom constants: msoScaleFromBottomRight, msoScaleFromMiddle, or msoScaleFromTopLeft. The default value is msoScaleFromTopLeft. Putting It Together
REFERENCESFor more information about using the sample code in this article, click the article number below to view the article in the Microsoft Knowledge Base: Q212536 OFF2000: How to Run Sample Code from Knowledge Base Articles Additional query words: vba change alter color scale move shapes modify autoshapes powerpoint slideshow colors rgb red green blue howto how to ppt ppt9 9.0 ppt2k 2k ppt2000 2000
Keywords : kbdta kbdtacode OffVBA KbVBA |
Last Reviewed: October 8, 1999 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |