Solved

Text box properties via a macro / automation

Posted on 2004-08-06
8
573 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
  • 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

I would like to show you some basics you can do with Mailings in MS Word. It´s quite handy feature you can use for creating envelopes, labels, personalized letters etc. First question could be what is this feature good for? Mailing can really he…
Preface: When I started this series, I used the term CommandBars because that is the Office Object class that it discusses. Unfortunately, when Microsoft introduced Office 2007, they replaced the standard Commandbar menus with "The Ribbon" and rem…
Learn how to create and modify your own paragraph styles in Microsoft Word. This can be helpful when wanting to make consistently referenced styles throughout a document or template.
This Micro Tutorial well show you how to find and replace special characters in Microsoft Word. This is similar to carriage returns to convert columns of values from Microsoft Excel into comma separated lists.

803 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