Solved

Text box properties via a macro / automation

Posted on 2004-08-06
8
570 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
 
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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Introduction Authors who set out to write any sort of lengthy piece for online submission—be it a long question or comment on a technical form, an article, or a substantial blog entry—often find it useful to work up a draft in an editor other t…
It is often necessary in this forum and others to illustrate Word fields as text with the field delimiters replaced with the curly brackets that the delimiters resemble when field codes are being displayed on the document. This means that the text c…
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.
In a previous video Micro Tutorial here at Experts Exchange (http://www.experts-exchange.com/videos/1358/How-to-get-a-free-trial-of-Office-365-with-the-Office-2016-desktop-applications.html), I explained how to get a free, one-month trial of Office …

759 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now