Text box properties via a macro / automation

I'd like to create a macro (or VBA code or an Active/X contron or any similar construct) that, when invoked allows me to set the properties of a text-box in a given document.

Specifically, I'd like to access and set the values on the "Format Text Box" property pages via an alternative interface.  Say, a dialog that contains several of the properties grouped together.
LVL 11
Who is Participating?
Joanne M. OrzechConnect With a Mentor Manager, Document Services CenterCommented:
In VBA, Insert, UserForm.

Create your user form from there with the items you want.

Double click on your OK button and the code goes under there.

Joanne M. OrzechManager, Document Services CenterCommented:
You may be able to create a custom toolbar with some of the options from the Format Text Box dialog.  I think you could drag most of them from Tools, Customize, Commands, Drawing - if I'm understanding you properly.  There may be a more elegant way out there...but that's just off the top of my head.

Otherwise, sample code for a drawing object:
Sub FormatTB()
    ActiveDocument.Shapes("Text Box 1").Select
    Selection.ShapeRange.Fill.Visible = msoTrue
    Selection.ShapeRange.Fill.ForeColor.RGB = RGB(51, 204, 204)
    Selection.ShapeRange.Fill.Transparency = 0#
    Selection.ShapeRange.Line.Weight = 0.75
    Selection.ShapeRange.Line.DashStyle = msoLineSolid
    Selection.ShapeRange.Line.Style = msoLineSingle
    Selection.ShapeRange.Line.Transparency = 0#
    Selection.ShapeRange.Line.Visible = msoTrue
    Selection.ShapeRange.Line.ForeColor.RGB = RGB(255, 0, 255)
    Selection.ShapeRange.Line.BackColor.RGB = RGB(255, 255, 255)
    Selection.ShapeRange.LockAspectRatio = msoTrue
    Selection.ShapeRange.Height = 72#
    Selection.ShapeRange.Width = 221.75
    Selection.ShapeRange.TextFrame.MarginLeft = 7.2
    Selection.ShapeRange.TextFrame.MarginRight = 7.2
    Selection.ShapeRange.TextFrame.MarginTop = 3.6
    Selection.ShapeRange.TextFrame.MarginBottom = 3.6
    Selection.ShapeRange.RelativeHorizontalPosition = _
    Selection.ShapeRange.RelativeVerticalPosition = _
    Selection.ShapeRange.Left = InchesToPoints(0)
    Selection.ShapeRange.Top = InchesToPoints(0)
    Selection.ShapeRange.LockAnchor = False
    Selection.ShapeRange.WrapFormat.AllowOverlap = True
    Selection.ShapeRange.WrapFormat.Side = wdWrapBoth
    Selection.ShapeRange.WrapFormat.DistanceTop = InchesToPoints(0)
    Selection.ShapeRange.WrapFormat.DistanceBottom = InchesToPoints(0)
    Selection.ShapeRange.WrapFormat.DistanceLeft = InchesToPoints(0.13)
    Selection.ShapeRange.WrapFormat.DistanceRight = InchesToPoints(0.13)
    Selection.ShapeRange.WrapFormat.Type = wdWrapTight
End Sub
alexoAuthor Commented:
I am a complete novice with regards to Word automation and object model (ss there a good tutorial on the web?) so please provide more details.

Is it possible to:
1. use a dialog to let the user set the properties
2. invoke it on an existing text box (select with the mouse, click on the macro button, dialog pops up)
3. similarly create a new text-box

Is there a list of the properties?  For example how do I set the wrapping style to "in front of text"?

Also, how do I set the web / alternative text ?

Thank you.
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

Joanne M. OrzechManager, Document Services CenterCommented:
Your best bet would be to just record a macro setting the properties you want - I hope I'm not getting off track here.... just record the macro and then look at it (Alt F11) and you can see the code there.

And I don't understand what you mean by "set the web / alternative text"  sorry...
alexoAuthor Commented:

OK, I'll try to continue from there.

Just one clarification:

How do I present a dialog and use its values for the ShapeRange roperties?
Joanne M. OrzechManager, Document Services CenterCommented:
I believe the above are all the properties.

For example how do I set the wrapping style to "in front of text"?

Selection.ShapeRange.WrapFormat.Type = 3
Joanne M. OrzechManager, Document Services CenterCommented:
Thanks very much alexo.
alexoAuthor Commented:
you are welcome.
it was not a very difficult question but I have points to spare so why not... :-)
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.