?
Solved

Text box properties via a macro / automation

Posted on 2004-08-06
8
Medium Priority
?
584 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
Tech or Treat!

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

 
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 2000 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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

Do you ever need to create a 20 page Word document for some testing purpose? Are you tired of copying & pasting old boring "lorem ipsum" text over and over again, increasing font size and line space in order to make the document 20+ pages long? Look…
A few years ago I was very much a beginner at VBA, and that very much remains the case today.  I'll do my best to explain things as I go in the hope that other beginners can follow.  If you just want to check out a tool that creates a Select Case fu…
This video teaches the viewer how to align pictures around text while keeping the text properly aligned in the document.
This video shows the viewer how to set up and create Footnotes in their document. Click on the References tab: Select "Insert Footnote": Type in desired text:
Suggested Courses

649 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