Microsoft Office Automation with Visual FoxPro
Backgrounds
The plain white background on all slides is something your clients will insist that you change. You can set backgrounds individually on every slide, but that s a lot of redundant code, and it s a big performance hit. One of the first SlideMaster properties to explore is the Background property. This sets the background of all slides to be the same using a minimum of code with maximum performance.
The Background property stores a ShapeRange object. While the ShapeRange object has a number of properties, the most useful from the Background property s viewpoint is the Fill property, which references a FillFormat object, the same object used to fill shapes. You can fill the background with solid, soft yellow like this:
#DEFINE rgbSoftYellow RGB(255,255,192)
oPresentation.SlideMaster.Background.Fill.ForeColor.RGB = rgbSoftYellow
To provide a patterned background, set the ForeColor and BackColor properties of the FillFormat object. Then use the Patterned method, which accepts one parameter, a numeric value corresponding to the pattern (msoPattern constants). The Pattern property is set to the same value you pass to the Patterned method.
#DEFINE msoPatternDottedGrid 45
#DEFINE rgbDarkGray RGB(128, 128, 128)
#DEFINE rgbMediumGray RGB(192, 192, 192
* For a Patterned Background:
WITH oPresentation.SlideMaster.Background.Fill
.ForeColor.RGB = rgbDarkGray
.BackColor.RGB = rgbMediumGray
.Patterned(msoPatternDottedGrid)
ENDWITH
This code produces a medium gray slide with a dotted grid (about every eight pixels) in dark gray. We re not sure this is the most aesthetically pleasing background the pattern is too small and busy to use for projected slides. The Pattern tab on the Fill Effects dialog box in Figure 1 shows examples of the patterns. Use of patterns may best be left to smaller shapes, which can handle smaller patterns.
Figure 1. The Fill Effects dialog box. This dialog shows samples of the available patterns.
Textures
If you or your client has used PowerPoint for very long, you know (or will soon be informed by your client) that there are textured backgrounds. Office provides about 25 preset textures to use. The FillFormat s PresetTextured method sets the background to the specified texture.
#DEFINE msoTextureSand 8
oPresentation.SlideMaster.Background.Fill.PresetTextured(msoTextureSand)
This line of code sets the background to a deep sand texture. If you want to find out what texture is in use, use the read-only PresetTexture property to return the numeric value.
What if your client wants a custom texture? Not to worry, PowerPoint provides a UserTextured method. This method takes one parameter, which is the fully qualified filename of a picture file to tile across the background. This filename is stored in the TextureName property (read-only). The TextureType property indicates which kind of texture is in use. The TextureType property returns msoTexturePreset (1) or msoTextureUserDefined (2).
Picture fills
You can use a bitmap as a background, too. The UserPicture method accepts a parameter consisting of a fully qualified bitmap filename. It forces the bitmap to take up the entire background it does not tile it (use the UserTextured method to tile it). It uses some interesting smoothing techniques when you try to stretch a small bitmap across the whole slide. For an example, you might try:
oPresentation.SlideMaster.Background.Fill.UserPicture( ;
GETENV("WINDIR" + "\TILES.BMP"))
This is a small bitmap that resembles brick; when enlarged, it has kind of a futuristic red and black look. This won t win any visual awards, but it is a striking example of how a small bitmap is smoothed over the whole screen. There isn t a documented property that corresponds to the UserPicture method to tell you what bitmap is used.
Gradient fills
Perhaps the most sought after background is the gradient fill you know the kind, a nice medium blue fades from the top to a nearly black color at the bottom. Figure 2 shows the PowerPoint dialog box that allows you to select the gradient fills interactively. This is a handy cue to remember all the various properties for setting a gradient fill.
There are three gradient color types available in PowerPoint. The GradientColorType property stores the currently selected gradient type. It is a read-only property; separate methods are used to set the gradient. This is to your benefit, as the methods used to set each type take multiple parameters, ensuring that you set all the necessary properties for the specific gradient. Here are the three gradient color types:
- Preset colors: usually employing three or more colors, there are 24 presets that have names like Daybreak, Ocean, Fog, Moss, Wheat, and Parchment (which, incidentally, are the most professional looking schemes; the rest can look very garish depending on the text colors used).
- One-color fill: the selected color graduates to shades of the same color that are lighter or darker than the selected color (as light as white or as dark as black).
- Two-color fill: the first color graduates into the second color.
Figure 2. PowerPoint s gradient fill option dialog box. This is a handy visual reminder of the properties that need to be set for a gradient fill.
The preset colors are set with the PresetGradient method. This method takes three parameters:
oPresentation.SlideMaster.Background.Fill.PresetGradient(nStyle, nVariant, nType)
NStyle | Numeric | Indicates the shading style of the gradient: | |||
msoGradientDiagonalDown | 4 | msoGradientDiagonalUp | 3 | ||
msoGradientFromCenter | 7 | msoGradientFromCorner | 5 | ||
msoGradientFromTitle | 6 | msoGradientHorizontal | 1 | ||
msoGradientVertical | 2 | ||||
nVariant | Numeric | Indicates the choice of color order (no constants): | |||
1 = Color 1 to Color 2 (top left box in the gradient dialog) | |||||
2 = Color 2 to Color 1 (top right box in the gradient dialog) | |||||
3 = Color 1 to Color 2 back to Color 1 (lower left box in the gradient dialog) | |||||
4 = Color 2 to Color 1 back to Color 2 (lower right box in the gradient dialog) | |||||
nType | Numeric | Indicates the preset color scheme. Some of the 24 are: | |||
msoGradientDaybreak | 4 | msoGradientOcean | 7 | ||
msoGradientFog | 10 | msoGradientParchment | 14 | ||
msoGradientMoss | 11 | msoGradientWheat | 13 |
Most clients may object to the preset colors. As stated before, many are garish, and those that are professional are probably overused by their competitors. Your client may be more sophisticated than the preset colors (by the way, this is an excellent argument to dissuade a client who chooses one of the garish presets take a look at the Rainbow type [16] to see what we mean).
The next gradient type is the one-color gradient, which uses the OneColorGradient method to set the appropriate properties. Like the PresetGradient method, it also takes three parameters; the first two are identical to the PresetGradient method:
oPresentation.SlideMaster.Background.Fill.OneColorGradient(nStyle, nVariant, nDegree)
nStyle | Numeric | The shading style of the gradient. See PresetGradient for constants. |
nVariant | Numeric | The choice of color order. See PresetGradient for values. |
nDegree | Numeric | A value from 0 to 1, representing the darkness of the resulting color. 0 is black, and 1 is white; .25 is a dark shade of the color, and .75 is a pale shade of the color. Represents Color 2. |
Notice that there is no mention of what color to use as Color 1. The ForeColor property is used for Color 1. To set the background color on the slide to go from a medium royal blue to a pale shade of the same blue, use the following code:
#DEFINE msoGradientHorizontal 1
#DEFINE rgbMediumBlue RGB(0, 0, 150)
WITH oPresentation.SlideMaster.Background.Fill
.ForeColor.RGB = rgbMediumBlue
.OneColorGradient(msoGradientHorizontal, 1, .75)
ENDWITH
The final gradient type is the two-color gradient. Yep, you guessed it: use the TwoColorGradient method. This one only takes two parameters:
oPresentation.SlideMaster.Background.Fill.TwoColorGradient(nStyle, nVariant)
nStyle | Numeric | The shading style of the gradient. See PresetGradient for constants. |
nVariant | Numeric | The choice of color order. See PresetGradient for values. |
The two colors are set by the Foreground and Background colors. The following example sets the color to graduate from a royal blue to a pale teal:
#DEFINE msoGradientHorizontal 1
#DEFINE rgbMediumBlue RGB( 0, 0, 150)
#DEFINE rgbPaleTeal RGB(192, 255,255)
WITH oPresentation.SlideMaster.Background.Fill
.ForeColor.RGB = rgbMediumBlue
.BackColor.RGB = rgbPaleTeal
.TwoColorGradient(msoGradientHorizontal, 1)
ENDWITH
Since you re setting a series of properties by calling methods, just what properties are you setting? Table 1 shows the FillFormat s properties that are set through each method. These are all read-only properties that can be queried to determine what the current settings are. Be sure to check the GradientColorType property first, then query only the properties that are applicable to the gradient type. Unused properties (such as GradientDegree, if a preset or two-color gradient type) are not reset to a default value when the gradient type is changed. For example, determining that the GradientDegree is .75 does not guarantee that a one-color gradient is used you must query GradientColorType to be sure.
Table 1. The Gradient properties of the FillFormat object. Each type of gradient uses most of the Gradient properties but not all. Check GradientColorType to ensure you set the appropriate properties for the gradient fill.
Property | PresetGradient | OneColorGradient | TwoColorGradient |
GradientColorType | msoGradientPresetColors (3) | msoGradientOneColor (1) | msoGradientTwoColors (2) |
GradientStyle | nStyle parameter | nStyle parameter | nStyle parameter |
GradientVariant | nVariant parameter | nVariant parameter | nVariant parameter |
GradientDegree | NA | 0 (black) 1 (white) | NA |
PresetGradientType | nType parameter | NA | NA |
All the types of backgrounds (solid, patterned, picture, textured, and gradient) set properties through the FillFormat s methods. Table 2 shows a compilation of all the properties that are set or used with each method. Remember, setting to a different background does not reset any unused properties to a default. Query the FillFormat s Type property to ensure which background format is in use.
Table 2. The FillFormat properties set by the various FillFormat methods. Remember that the Type property is the only indicator of the background format in use do not rely on values in the other properties solely to determine the type of background format.
Property | Solid | Patterned | Preset Texture | User Defined Texture | UserPicture | Preset Gradient | One Color Gradient | Two Color Gradient |
Read Only | ||||||||
Type | msoFillSolid (1) | msoFillPatterned (2) | msoFillTextured (4) | msoFillTextured (4) | msoFillPicture (6) | msoFillGradient (3) | msoFillGradient (3) | msoFillGradient (3) |
Pattern | - | msoPattern constants | - | - | - | - | - | - |
TextureType | - | - | msoTexturePreset (1) | msoTextureUserDefined (3) | - | - | - | - |
PresetTexture | - | - | msoTexture constants | - | - | - | - | - |
TextureName | - | - | - | BMP filename | - | - | - | - |
GradientColorType | - | - | - | - | - | msoGradientPresetColors (3) | msoGradientOneColor (1) | msoGradientTwoColors (2) |
GradientStyle | - | - | - | - | - | nStyle | nStyle | nStyle |
GradientVariant | - | - | - | - | - | nVariant | nVariant | nVariant |
PresetGradientType | - | - | - | - | - | nType | - | - |
GradientDegree | - | - | - | - | - | - | 0.0-1.0 | - |
Read/Write | ||||||||
ForeColor | ü | ü | - | - | - | - | ü | ü |
BackColor | - | ü | - | - | - | - | - | ü |
Copyright 2000 by Tamar E. Granor and Della Martin All Rights Reserved