Hi courtesio99,
You can use the macro recorder and mouse to build shapes, but it's extremely
limited, and produces enormous thickets of code, because the recorder logs every
characteristic of the shape being created or modified, whether you change it or
not. It's also a big chore to use the recorder to do anything else noteworthy,
like modify an existing shape when your document has several.
In VBA you typically want to approach this by writing code rather than recording
it, which is a very different process with shapes -- though extremely powerful
once you master it. You may still find use for the macro recorder, but just to
record bits of code to help you discover what properties and methods to use for
certain tasks.
Usually in VBA, you build a shape by (1) defining an object variable as the
newly added shape, and then (2) setting its various properties. Step (1) is
what sets apart the code-writing method from the recording method, and what
gives it much of its power. For example, the macro below will draw a
4-inch-diameter circle with the upper left corner of its bounding rectangle 2"
from the top of the page and 2" from the left edge. Then it gives the shape it
a color ("fill") of red and a 12-point-thick yellow border ("line").
Dim sh As Shape
Set sh = ActiveDocument.Shapes.AddShape(Type:=msoShapeOval, _
Left:=144, Top:=144, Width:=288, Height:=288)
With sh
.Line.Weight = 12
.Line.ForeColor = vbYellow
.Fill.ForeColor = vbRed
End With
(Most graphics measurements in VBA are given in points, so a width of 288 is 4
inches. 1 inch = 72 points.)
I should pause here to point out that, if you're really *totally new to macros,"
building shapes in VBAA code may not be the greatest place to start. It can't
hurt, but don't be discouraged if it seems miles above your head. Once you get
comfortable with the more pedestrian uses of VBA, it won't look so weird.
Building the above shape by recording a macro would spit out over 30 lines of
code, specifying every parameter you could *possibly* have adjusted in the
dialogs you would have used. (Try it.) (The one thing it's handy for is
finding out what VBA calls the shape, e.g., msoShapeOval above, since some of
the more obscure shapes have names you can't always guess at.)
But that's not the main difference. Say you needed to create 20 shapes in a
document and then perhaps go back and change one of them later, you'd have a
horrible time writing code to find that one if you'd used recorded code to build
it. But when you *write* the code, you can NAME your shapes, and those names
will stick.
All shapes have a built-in name assigned by Word, but they're much less useful
than a name you assign. (To illustrate, select any manually drawn shape and run
a macro like:
MsgBox Selection.ShapeRange(1).Name
The red circle I built above is called "Oval 4." Bleah.)
But if we just add a line like:
.Name = "Mars"
to the macro first shown above, after the "With sh" line, it places a permanent,
easily remembered handle on the shape, which you can use later, even in
another macro at another time. So I could come back to this document and use
the macro below to re-color the shape and add an informative message to the
shape itself:
With ActiveDocument.Shapes("Mars")
.Fill.ForeColor = vbYellow
.TextFrame.TextRange.Text = "But I'm not Mars, I'm the Sun!"
End With
Hope this helps a bit and doesn't overwhelm.