wdStoryType Help!

A

AZ

Not sure if this is the right NG?

We have a scenario where the document contains a table
with N number of cells, each of which includes TextBoxes &
nested tables.
The program can deal (populates) with all the bits (custom
merge fields) outside the TextBox by selecting the table
cell and using Range to point to Selection.Range but we
have a problem dealing with the contents of TextBoxes.

How can we overcome this problem?
WdStoryType, covers all levels (stories) within a
document. This applies to the entire document, how can we
apply this to a selected Range (cell)? or is there another
way?

regards
 
J

Jay Freedman

Hi, AZ,

The story type really doesn't have anything to do with it...

A textbox is considered a Shape object, like a floating picture. If it's
anchored in a table cell, then it's a member of the ShapeRange collection
that belongs to the cell's .Range property.

As an example, if the textbox is anchored in the cell at row 1, column 2 of
the first table in the document, you can change the color of the second word
of the textbox's text this way:

Dim oRgTbl As Range, oRgBx As Range
Set oRgTbl = ActiveDocument.Tables(1).Cell(1, 2).Range
Set oRgBx = oRgTbl.ShapeRange(1).TextFrame.TextRange
oRgBx.Words(2).Font.Color = wdColorRed

It gets more complicated if the textbox is in a cell of a table that's
nested inside another table, but in theory you can just drill down through
the object hierarchy as far as you need to.
 
A

AZ

Thanks Jay,

Can you be patient enough to tell me how to anchor the
TextBox to the cell within the table and if this cell is
replicated would Word keep the anchor information as well?

regards
 
J

Jay Freedman

Hi, AZ,

Manually (without a macro), just put the cursor in the cell, click Insert >
Text Box, and drag a rectangle in the cell. If you check the "Object
anchors" box in Tools > Options > View, you'll be able to see the anchor
symbol whenever the textbox is selected -- although, confusingly, it's to
the left of the actual anchor point so it appears to be in the next cell to
the left.

Trying to program this is extremely infuriating. You have to use the
..Information method of the cell's .Range property to compute the position of
the cell in points from the top left corner of the page, and tell the
..InsertTextBox function the proper Left and Top values to place it inside
the cell. As far as I can tell, the Anchor value of that function is
completely broken.

If you copy the cell contents and paste it into another cell, the textbox
will be duplicated, and the anchor of the duplicate will be in the new cell.
This is true whether you do it manually or by code such as

With ActiveDocument.Tables(1)
.Cell(1, 1).Range.Copy
.Cell(2, 3).Range.Paste
End With
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top