How to deselect floating text box

V

Vivian Carroll

In Word 2000 I have a floating text box in a cell of an many-row table. I
am trying to create a macro that will delete the box, the paragraph mark
that it is anchored to, and the 3 blank paragraphs after it (all in the same
cell). "Selection.ShapeRange.Delete" will delete the text box, but the
cursor jumps to the top of the document. I tried some GoBack commands to
bring the cursor back to where the box had been but they don't always take
the cursor to the right location.

What I really want to do is start the macro with the text box already
selected by the user, then deselect the box and put the cursor immediately
in front of it so I can delete the paragraph containing it. What code do I
use to that is equivalent to "deselect the text box and put the cursor
immediately before the box"? ("Collapse" puts the cursor in front of the
text that is in the box, not before the box.)

TIA,

Vivian
 
J

Jonathan West

Hi Vivian,

Define a Range object variable and set it to the anchor of the textbox.
Then, even if the Selection jumps when you delete the textbox, you can still
locate its former anchor.

--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
 
V

Vivian Carroll

Thanks Jonathan,

I'll have to see if I can figure out how to do that!

Vivian
 
J

Jean-Guy Marcil

Vivian Carroll was telling us:
Vivian Carroll nous racontait que :
Thanks Jonathan,

I'll have to see if I can figure out how to do that!

Hers's a little something to get you going:

'_______________________________________
Dim BoxRange As Range

Set BoxRange = Selection.ShapeRange(1).Anchor

Selection.Delete
BoxRange.Select
'_______________________________________

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
V

Vivian Carroll

Thank you Jean-Guy,

You saved me a lot of time by providing the code that you did. I added one
more line to it and it works as I wanted it to!

Vivian
 

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