PPT2000: How to Change Shape Properties During Slide Show

ID: Q241792


The information in this article applies to:
  • Microsoft PowerPoint 2000


SUMMARY

Using 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 INFORMATION

Microsoft 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 Shape

You 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:

ActivePresentation.Slides(1).Shapes("Rectangle 2").Fill.ForeColor _
   .SchemeColor = ppAccent1 
There are eight different scheme colors to choose from:
  • ppBackground
  • ppForeground
  • ppShadow
  • ppTitle
  • ppFill
  • ppAccent1
  • ppAccent2
  • ppAccent3
The ppForeground color corresponds to the Text and Lines color selection inside the color scheme dialog box. There are two other color scheme types: ppNotSchemeColor and ppSchemeColorMixed. These color scheme types are not used for AutoShape objects.

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:

For c = 1 to 8
   .Fill.Forecolor.ScemeColor = c
   'other code placed here to do further changes to shape
next c 
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:

ActivePresentation.Slides(1).Shapes("Rectangle 2").Fill.ForeColor _ 
   .RGB = RGB(127, 127, 255) 
Using the RGB color model allows you to generate 16 million different colors easily. For reference to basic color values, use this chart:

Color Red value Green value Blue value
Black 0 0 0
Blue 0 0 255
Green 0 255 0
Cyan 0 255 255
Red 255 0 0
Magenta 255 0 255
Yellow 255 255 0
White 255 255 255

Altering the Size of a Shape

You 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:

With ActivePresentation.Slides(1).Shapes(1)
   .Height = 10
   .Width = 720
End With 
To resize around the center of the object, you would have to use the following code:

With ActivePresentation.Slides(1).Shapes(1)
   h = .Height
   w = .Width
   .Height = 10
   .Width = 720
   .Top = (h / 2) - (.Height / 2) + .Top
   .Left = (w / 2) - (.Width / 2) + .Left
End With 
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:

Sub ResizeIt()
   Dim h As Single
   Dim w As Single
   With ActivePresentation.Slides(1).Shapes(1)
      h = 1.5
      w = 1.5
      .ScaleHeight h, msoFalse, msoScaleFromMiddle
      .ScaleWidth w, msoFalse, msoScaleFromMiddle
   End With
End Sub 
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


Sub MoveToCenter()
   ' This code grabs the shape called "Rectangle 2" on slide 1
   ' of the presentation during a slide show.
   '
   With ActivePresentation.Slides(1).Shapes("Rectangle 2")
   
   ' This centers the rectangle, by subtracting half of its
   ' width and height from the values of 360 (half the screen
   ' width) and 270 (half the screen height.
   ' It then scales the object to twice its size, resizing
   ' around its center.
   '
      .Left = 360 - (.Width / 2)
      .Top = 270 - (.Height / 2)
      .ScaleHeight 2, msoFalse, msoScaleFromMiddle
      .ScaleWidth 2, msoFalse, msoScaleFromMiddle

   ' Change the fill color to a light blue.      
      .Fill.ForeColor.RGB = RGB(127, 127, 255)
   
   End With

   ' Refresh the slide on the screen.
   SlideShowWindows(1).View.GotoSlide 1, msoFalse
End Sub 


REFERENCES

For 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
Version : WINDOWS:2000
Platform : WINDOWS
Issue type : kbhowto


Last Reviewed: October 8, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.