AddTextBox Method - want to anchor it elsewhere in code.

J

J Pettigrew

Hello,

I have a situation where I add a text box in code and
position it on the page.
This code works perfectly as it stands:

ActiveDocument.Shapes.AddTextbox(msoTextOrientationHorizontal,
88#, _
637.35, 445.35, 35.3).Select

BUT

It places the anchor on the last paragraph mark on the
page. I do not want this (even if I tell it not to move the
anchor with the text, it still takes the textbox to page 2
when that paragraph mark is moved to a second page in the
document). It must be attached to a bookmark higher up on
the page.
According to the online help, there is an optional variant
I can add in the arguments to position or attach the anchor
to a range object.

This is quoted from the VBA help (and is reiterated in the
KBase) "Anchor - Optional Variant. A Range object that
represents the text to which the text box is bound. If
Anchor is specified, the anchor is positioned at the
beginning of the first paragraph in the anchoring range.
If this argument is omitted, the anchoring range is
selected automatically and the text box is positioned
relative to the top and left edges of the page."

There is no example of how this can be achieved, and I need
to attach the anchor to the bookmark. I have tried
everything, yet I'm unsuccessful.

This has been tried in Word 97, 2000, 2002 and 2003. Same
results in all versions. (and don't ask, but the client
needs it to work in all 4 versions. The addtextbox method
has not changed since 97, so I'm thinking that if I
can get it to work, it will work in all these versions).

I would be appreciative of any help you can suggest.
I really just need to attach the anchor to a bookmark. Oh,
and this text must go into a textbox, there is no other
alternative (we don't mention frames around here)

replies to the group, or to the following address:
(e-mail address removed)
<remove no.spam>

Thank you in advance
JP
 
J

Jay Freedman

Hi JP,

As the optional last argument of the AddTextbox method, insert

ActiveDocument.Bookmarks("bookmarkname").Range

(or assign that expression to a Range object that you declare in a Dim
statement, and then use that object in the AddTextbox method).

As an aside, with that many arguments, I'd recommend using the "named
arguments" syntax for future legibility. That would make it something
like this:

Dim rgBookMark As Range
Set rgBookMark = ActiveDocument.Bookmarks("bookmarkname").Range
ActiveDocument.Shapes.AddTextbox( _
Orientation:=msoTextOrientationHorizontal, _
Left:=88#, Top:=637.35, _
Width:=445.35, Height:=35.3, _
Anchor:=rgBookMark).Select

As far as I'm aware, this should work in all versions back to Word 97.
 

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