In this project we will create a 'FUN' macro that will demonstrate the use of 'Objects' and their 'Properties'.
- Enter some text into WORD, then open the VB Editor.
- Start a new macro with the name 'funfont', then enter the text "Selection."
Sub funfont() Selection. End Sub
- You will notice that as you entered the period '.', a dialog box will open with a list of all the available properties for the object you are using. Scroll down the list until you see 'Font' and double click on it. The property will be appended to your code.
Sub funfont() Selection.Font End Sub
- Enter a period '.' again, and a dialog box will open with a list of properties for the 'Selection.Font' object. Scroll down the list until you see 'ColorIndex' and double click on it. The property will be appended to your code.
Sub funfont() Selection.Font.ColorIndex End Sub
- If you entered a period '.' again, the dialog box will NOT open, indicating that you now have to assign some value to the object property. Instead, enter a equal sign '='. A dialog box will open with a list of 'values' for the 'Selection.Font.ColorIndex' object. Scroll down the list until you see 'wdBrightGreen' and double click on it. The value will be appended to your code.
Sub funfont() Selection.Font.ColorIndex=wdBrightGreen End Sub
- Now repeat the above procedure to add some more changes to the selected font, such as 'animation' and increased 'spacing'. It should look like the following for example ... Sub funfont()
Selection.Font.ColorIndex = wdBrightGreen Selection.Font.Animation = wdAnimationSparkleText Selection.Font.Spacing = 10 End Sub
- To finish the project, use the 'with' statement to reference the object 'Selection.Font', rather that reiterate it on each line of code.
- GOOD LUCK!
NOTE: Just delete the new macro when you have finished with it.
YOU HAVE NOW LEARNT HOW EASY IT IS TO USE OBJECTS AND THEIR PROPERTIES. ( AND HOPEFULLY HAD SOME FUN AS WELL! )
|