View Single Post
  #6   Report Post  
Posted to microsoft.public.word.docmanagement
Kimmie B
 
Posts: n/a
Default macro produces error message

Ah, I think we're getting somewhere.

Jay, I'm hoping you can indeed pick up where Cindy left off, and I thank you
in advance for the intellect that you apply to this problem.

Here's a wrinkle: I have a graphic in the header of page 1, which I don't
want to delete, of course. The macro deleted the watermark from the FIRST
page, but not subsequent pages. Oddly, the macro did not delete the graphic
in the header of the first page.

I replaced the offending line of code with Jay's suggested code. Here's how
it looks with Jay's line replacing the error-producing line:

Sub watermark()
'
' watermark Macro
' Macro recorded 3/10/2006 by Kimmie B
'
ActiveDocument.Sections(1).Range.Select
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
Selection.HeaderFooter.Shapes(1).Select
Selection.Delete
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
End Sub


So the question now is this: How do I edit this macro code so that it 1)
keeps the graphic in the first page header, and 2) removes the watermark on
the first and subsequent pages?

Thanks very much,

Kimmie



"Cindy M -WordMVP-" wrote:

Hi ?B?S2ltbWllIEI=?=,

First of all, "what Jay said" :-)

Is there a way to know the object name for Word 2003's DRAFT watermark? If
so, I'll see if I can manipulate the VB script to find it.

You can get the name, and set the name, for a Shape using Word's object model.
For example, if the Shape is selected:

MsgBox Selection.ShapeRange.Name
Selection.ShapeRange.Name = "MyDraf****ermark"

It's possible for you to assing a name when the Shape is created/inserted.
Things can get tricky, though, when working with the HeaderFooter area, which
is why I hesitate to just show you some sample code. I'd rather base it on the
code you're already using, but unfortunately you haven't copied that into any
of your messages. OTOH, this is the last time I'll be on-line for some 10
days... So I hope Jay will jump back in and clear things up if I confuse you
:-) (Please note that the better place to ask macro questions is a word.vba
newsgroup or developer, as you'll find more people there conversant with what
you need.)

Dim shp as Word.Shape
Set shp = ActiveDocument.Shapes.AddPicture(arguments go here)
shp.Name = "MyDraf****ermark"

The important thing is to 1. declare the object variable (Dim x as Shape),
then 2. set it to the Shape you're creating, no matter which ADD method you're
using on the Shapes collection. Once you do that, you can change all kinds of
things about the Shape, including the name.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or
reply in the newsgroup and not by e-mail :-)