Datasheet

Book IX
Chapter 1
Recording and
Using Macros
535
you insert into a document while recording a macro is included in a
Selection.TypeText command, like this:
Selection.TypeText Text:=”This is some simple text.”
You can correct any spelling mistakes or change the inserted text alto-
gether, as long as you take care not to remove either of the quotation
marks that appear before and after the text. For example, you can cor-
rect the preceding line this way:
Selection.TypeText Text:=”This is some sample text.”
Remove extraneous commands. If you inadvertently used a command
while recording a macro, you can clean up your macro by removing the
unnecessary command.
Remove unwanted dialog box settings. If you record a dialog box in a
macro, Word includes every setting in the dialog box. You can remove
the settings that you don’t want the macro to change. For example, if
you use the Font dialog box to format text in small caps, Word inserts
the following commands into the macro:
With Selection.Font
.Name = “Times New Roman”
.Size = 9.5
.Bold = False
.Italic = False
.Underline = wdUnderlineNone
.UnderlineColor = wdColorAutomatic
.StrikeThrough = False
.DoubleStrikeThrough = False
.Outline = False
.Emboss = False
.Shadow = False
.Hidden = False
.SmallCaps = True
.AllCaps = False
.Color = wdColorAutomatic
.Engrave = False
.Superscript = False
.Subscript = False
.Spacing = 0.3
.Scaling = 100
.Position = 0
.Kerning = 0
.Animation = wdAnimationNone
End With
This command looks complicated at first, but if you study it, you see
that it’s little more than a list of all dialog box controls that appear in
the Font dialog box. The periods look strange appearing in front of each
command argument as they do, but they’re required. You can safely
Simple Macro Edits That Don’t Require a PhD in VBA
50_487662-bk09ch01.indd 53550_487662-bk09ch01.indd 535 4/15/10 9:18 PM4/15/10 9:18 PM