Insert autotext containing text box, print, then delete

  • Thread starter Oli Restorick [MVP]
  • Start date
O

Oli Restorick [MVP]

I've followed Dian Chapman's excellent article (link follows) about creating
automating watermarks in Word. Thanks, Dian!

http://pubs.logicalexpressions.com/Pub0009/LPMArticle.asp?ID=456

Dian's suggestion for removing watermarks is to insert the watermark into
the header so that you can subsequently select and delete the header. Some
of the documents I need to use this solution with have text in the header or
footer, which I don't want to touch.

The current version of my macro inserts two text boxes on page 1 of the
current document and prints the current document. After printing, I want
the macro to delete the two text boxes.

I've been trying to insert the text boxes into a bookmark -- didn't work.
I'm also unsure how I should go about deleting the last two things that were
inserted if they are anything other than ordinary characters. Is ShapeRange
useful here?

The best I have come up with is to issue the Undo command twice. However,
this sometimes seems to delete only one of the text boxes. I want to be
sure I select the right thing every time.

Any ideas?

Thanks

Oli
 
J

Jean-Guy Marcil

Oli Restorick [MVP] was telling us:
Oli Restorick [MVP] nous racontait que :
I've followed Dian Chapman's excellent article (link follows) about
creating automating watermarks in Word. Thanks, Dian!

http://pubs.logicalexpressions.com/Pub0009/LPMArticle.asp?ID=456

Dian's suggestion for removing watermarks is to insert the watermark
into the header so that you can subsequently select and delete the
header. Some of the documents I need to use this solution with have
text in the header or footer, which I don't want to touch.

The current version of my macro inserts two text boxes on page 1 of
the current document and prints the current document. After
printing, I want the macro to delete the two text boxes.

I've been trying to insert the text boxes into a bookmark -- didn't
work. I'm also unsure how I should go about deleting the last two
things that were inserted if they are anything other than ordinary
characters. Is ShapeRange useful here?

The best I have come up with is to issue the Undo command twice. However,
this sometimes seems to delete only one of the text boxes. I want to be
sure I select the right thing every time.

Any ideas?

Give a name to the shape when you create it, then you can delete it by name:

Dim myShape As Shape

Set myShape = ActiveDocument.Shapes.AddShape(msoShapeRectangle, _
0, 0, 200, 100, Selection.Range)

With myShape
.Name = "MyFirstShape"
'Do other stuff with it
End With

myShape.Delete


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

Oli Restorick [MVP]

Thanks for your reply.

The text box itself isn't created directly with a macro. I created the text
box interactively. The contents of the text box are too complex to code
with a macro, and I want the flexibility of being able to update it
interactively.

I then selected the text box and pressed Alt-F3 to create an autotext entry
for the text box. It is this autotext that gets inserted by my macro.

Therefore, I can't see a way to name the text box. Any suggestions?

Oli
 
O

Oli Restorick [MVP]

Thanks, but that is what I currently do. As I said in my first post, this
leads to inconsistent results. I'm not sure why, but in some circumstances
only one of the two text boxes is removed.

Oli
 
J

Jean-Guy Marcil

Oli Restorick [MVP] was telling us:
Oli Restorick [MVP] nous racontait que :
Thanks for your reply.

The text box itself isn't created directly with a macro. I created
the text box interactively. The contents of the text box are too

What do you mean by "interactively"?
It still has to be created, no? Whenever you create it, give it a name.
complex to code with a macro, and I want the flexibility of being
able to update it interactively.

I then selected the text box and pressed Alt-F3 to create an autotext
entry for the text box. It is this autotext that gets inserted by my
macro.

If it is already "hardcoded" as part of the document,
insert it once, select it and run this code to give it a name:

'_______________________________________

Selection.ShapeRange(1).Name = "myTextBox"
'_______________________________________

You can delete this code and delete the shape after recreating the autotext.
The name will stick in the autotext.

Then use this to delete it in the other code:
'_______________________________________

ActiveDocument.Shapes("myTextBox").Delete
'_______________________________________

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

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