Solved

Text box properties via a macro / automation

Posted on 2004-08-06
8
576 Views
Last Modified: 2012-05-05
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.
0
Comment
Question by:alexo
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
8 Comments
 
LVL 37

Expert Comment

by:Joanne M. Orzech
ID: 11742526
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.Solid
    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 = _
        wdRelativeHorizontalPositionColumn
    Selection.ShapeRange.RelativeVerticalPosition = _
        wdRelativeVerticalPositionParagraph
    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
0
 
LVL 11

Author Comment

by:alexo
ID: 11743002
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.
0
 
LVL 37

Expert Comment

by:Joanne M. Orzech
ID: 11743067
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...
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 11

Author Comment

by:alexo
ID: 11743290
Selection.ShapeRange.AlternativeText

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?
0
 
LVL 37

Accepted Solution

by:
Joanne M. Orzech earned 500 total points
ID: 11743418
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.

http://word.mvps.org/FAQs/MacrosVBA/index.htm
0
 
LVL 37

Expert Comment

by:Joanne M. Orzech
ID: 11755760
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
0
 
LVL 37

Expert Comment

by:Joanne M. Orzech
ID: 11755911
Thanks very much alexo.
0
 
LVL 11

Author Comment

by:alexo
ID: 11755943
you are welcome.
it was not a very difficult question but I have points to spare so why not... :-)
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There is a feature provided by MS Word that lets you create an Table of Contents for your Word document automatically. To use this feature for other documents there are two steps involved,   1.  Prepare your document for a table of contents (he…
The Selection object is designed for user interaction. It has a Range property, so it can be used in most places that a Range object can. Recorded macros must use the Selection because they are simply copying what the user is doing. A Range prope…
The viewer will learn how to make their project stand out over others by learning how to change colors and shapes, add spaces, change directions, and add bullets to their charts.
This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …
Suggested Courses

737 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question