Reply
 
Thread Tools Display Modes
  #1   Report Post  
Posted to microsoft.public.word.docmanagement
Kimmie B
 
Posts: n/a
Default macro produces error message

Hello smart Word people,
I'm trying to create a macro on a template that automatically removes the
DRAFT watermark from the document, and I want to add a button for this new
macro to the custom toolbar that already exists in the template.

Per Word online Help, I've tried Tools Macro Record New Macro, and
clicked the toolbar icon and recorded the steps for removig the watermark.

When I record the macro, the watermark disappears, as I expect it to.
However, when I later add the watermark back in to test the macro, and try to
use the button, I get a runtime error message ("the item with the specified
name wasn't found"). When I click the debug button, VB indicates the
following faulty code:
Selection.HeaderFooter.Shapes("PowerPlusWaterMarkO bject2").Select.

Also, the new macro does not appear when I select Tools Macro on the menu
bar.

What's going wrong?

Ideally, I'd like a macro button that lets the user toggle between having
the DRAFT watermark turned on and off, but right now I'd just settle for a
button that works properly to turn off the draft watermark.

Thanks in advance for your help,

Kimmie B



  #2   Report Post  
Posted to microsoft.public.word.docmanagement
Cindy M -WordMVP-
 
Posts: n/a
Default macro produces error message

Hi ?B?S2ltbWllIEI=?=,

I'm trying to create a macro on a template that automatically removes the
DRAFT watermark from the document, and I want to add a button for this new
macro to the custom toolbar that already exists in the template.

Per Word online Help, I've tried Tools Macro Record New Macro, and
clicked the toolbar icon and recorded the steps for removig the watermark.

When I record the macro, the watermark disappears, as I expect it to.
However, when I later add the watermark back in to test the macro, and try to
use the button, I get a runtime error message ("the item with the specified
name wasn't found"). When I click the debug button, VB indicates the
following faulty code:
Selection.HeaderFooter.Shapes("PowerPlusWaterMarkO bject2").Select.

Well... Every Shape (graphic object with text-flow formatting applied) has a
name. In the case of the macro you recorded, the name of the Shape (watermark)
was "PowerPlusWaterMarkObject2". The watermark you inserted later probably had a
different name, which is why you get the error message.

If you plan to be recreating/deleting the watermark, then you either have to
include giving it a name when it's created...

OR you have to specify it in a different manner. If this is the only graphic
object in the Header/Footer, try using Shapes(1) instead of the name.

Also, the new macro does not appear when I select Tools Macro on the menu
bar.

Not sure what the problem is, here. But macros can be stored in Normal.dot, in
the individual document on which you're working, that document's attached
template, or any global template. If you've saved the macro in one place, and
then selected something different from the "Macros in" list in this dialog box,
you may not see it in the list until you change this selection.

Ideally, I'd like a macro button that lets the user toggle between having
the DRAFT watermark turned on and off, but right now I'd just settle for a
button that works properly to turn off the draft watermark.


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 :-)

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

Thanks for the response Cindy. While your idea makes sense, in reality it
didn't work.

I changed the VB script to indicate
"Selection.HeaderFooter.Shapes("Shape1").Selec t." and got the same error
message.

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.

Alternatively, can anyone provide me with a macro that works for removing a
DRAFT watermark?

Thanks,

Kimmie

"Cindy M -WordMVP-" wrote:

Hi ?B?S2ltbWllIEI=?=,

I'm trying to create a macro on a template that automatically removes the
DRAFT watermark from the document, and I want to add a button for this new
macro to the custom toolbar that already exists in the template.

Per Word online Help, I've tried Tools Macro Record New Macro, and
clicked the toolbar icon and recorded the steps for removig the watermark.

When I record the macro, the watermark disappears, as I expect it to.
However, when I later add the watermark back in to test the macro, and try to
use the button, I get a runtime error message ("the item with the specified
name wasn't found"). When I click the debug button, VB indicates the
following faulty code:
Selection.HeaderFooter.Shapes("PowerPlusWaterMarkO bject2").Select.

Well... Every Shape (graphic object with text-flow formatting applied) has a
name. In the case of the macro you recorded, the name of the Shape (watermark)
was "PowerPlusWaterMarkObject2". The watermark you inserted later probably had a
different name, which is why you get the error message.

If you plan to be recreating/deleting the watermark, then you either have to
include giving it a name when it's created...

OR you have to specify it in a different manner. If this is the only graphic
object in the Header/Footer, try using Shapes(1) instead of the name.

Also, the new macro does not appear when I select Tools Macro on the menu
bar.

Not sure what the problem is, here. But macros can be stored in Normal.dot, in
the individual document on which you're working, that document's attached
template, or any global template. If you've saved the macro in one place, and
then selected something different from the "Macros in" list in this dialog box,
you may not see it in the list until you change this selection.

Ideally, I'd like a macro button that lets the user toggle between having
the DRAFT watermark turned on and off, but right now I'd just settle for a
button that works properly to turn off the draft watermark.


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 :-)


  #4   Report Post  
Posted to microsoft.public.word.docmanagement
Jay Freedman
 
Posts: n/a
Default macro produces error message

"Selection.HeaderFooter.Shapes("Shape1").Select ."

That is _not_ what Cindy told you to try. When you put "Shape1" in
quotes in the parentheses, that's telling VBA to look for a shape that
is literally named "Shape1". There obviously isn't any such shape.

What Cindy suggested should be written in full as

Selection.HeaderFooter.Shapes(1).Select

which refers to the first shape in the header, regardless of what its
name is.

--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.

On Thu, 9 Mar 2006 10:00:29 -0800, Kimmie B
wrote:

Thanks for the response Cindy. While your idea makes sense, in reality it
didn't work.

I changed the VB script to indicate
"Selection.HeaderFooter.Shapes("Shape1").Select ." and got the same error
message.

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.

Alternatively, can anyone provide me with a macro that works for removing a
DRAFT watermark?

Thanks,

Kimmie

"Cindy M -WordMVP-" wrote:

Hi ?B?S2ltbWllIEI=?=,

I'm trying to create a macro on a template that automatically removes the
DRAFT watermark from the document, and I want to add a button for this new
macro to the custom toolbar that already exists in the template.

Per Word online Help, I've tried Tools Macro Record New Macro, and
clicked the toolbar icon and recorded the steps for removig the watermark.

When I record the macro, the watermark disappears, as I expect it to.
However, when I later add the watermark back in to test the macro, and try to
use the button, I get a runtime error message ("the item with the specified
name wasn't found"). When I click the debug button, VB indicates the
following faulty code:
Selection.HeaderFooter.Shapes("PowerPlusWaterMarkO bject2").Select.

Well... Every Shape (graphic object with text-flow formatting applied) has a
name. In the case of the macro you recorded, the name of the Shape (watermark)
was "PowerPlusWaterMarkObject2". The watermark you inserted later probably had a
different name, which is why you get the error message.

If you plan to be recreating/deleting the watermark, then you either have to
include giving it a name when it's created...

OR you have to specify it in a different manner. If this is the only graphic
object in the Header/Footer, try using Shapes(1) instead of the name.

Also, the new macro does not appear when I select Tools Macro on the menu
bar.

Not sure what the problem is, here. But macros can be stored in Normal.dot, in
the individual document on which you're working, that document's attached
template, or any global template. If you've saved the macro in one place, and
then selected something different from the "Macros in" list in this dialog box,
you may not see it in the list until you change this selection.

Ideally, I'd like a macro button that lets the user toggle between having
the DRAFT watermark turned on and off, but right now I'd just settle for a
button that works properly to turn off the draft watermark.


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 :-)


  #5   Report Post  
Posted to microsoft.public.word.docmanagement
Cindy M -WordMVP-
 
Posts: n/a
Default macro produces error message

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 :-)



  #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 :-)


  #7   Report Post  
Posted to microsoft.public.word.docmanagement
Jay Freedman
 
Posts: n/a
Default macro produces error message

Hi Kimmie,

To answer this, we're going to have to dig deeper into how this
particular document is set up. If it's what I think it is, the macro
is going to need some fairly major surgery. That's not unusual for a
recorded macro -- I wrote a whole page on the topic
(http://www.word.mvps.org/FAQs/Macros...ordedMacro.htm) and
barely scratched the surface.

The first issue is the watermark vs. the other graphic in the header.
If the other graphic is in-line instead of floating, this won't be a
problem. An easy way to tell the difference is to open the header area
and click once on the graphic. If the "handles" in the corners and
edges of the graphic are black, it's in-line; if they're circles with
white centers, and there's a green handle above the graphic, then it's
floating.

The way this works in a macro is that floating graphics belong to the
Shapes collection, while in-line ones belong to the InlineShapes
collection. They're completely separate groups, so deleting any Shape
(which would be the watermark) won't touch any InlineShape.

If both the watermark and the other graphic are floating Shapes, then
there's a problem, because it's hard for the macro to know which one
is Shapes(1) and which is Shapes(2). It still might be possible, by
checking the value of the Type property of the Shape, but I hope to
avoid the need for that.

The second issue is the first page vs. other pages thing. There are
basically two ways this could happen, and you'll have to tell me which
is correct in your document. Look in the File Page Setup Layout
dialog and tell me whether the "Different odd and even" option is
checked. If not, the other way is if there's a section break between
pages 1 and 2, with headers that are not marked "Same As Previous", so
they can be different. (I'm betting on the odd/even situation.)

Instead of passing these hints back and forth, it might be quicker if
you can email a copy of the document (template?) to me.

--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.

On Fri, 10 Mar 2006 15:16:28 -0800, Kimmie B
wrote:

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 :-)


  #8   Report Post  
Posted to microsoft.public.word.docmanagement
Tony Jollans
 
Posts: n/a
Default macro produces error message

Watermarks produced by Format Background Watermark are strange beasts
and I'm not sure you're going to be able to do this at all but something
along these lines might switch them off ...

For each s in activedocument.sections
For each h in s.headers
For each w in h.shapes
If left(w.name,18) = "PowerPlusWatermark" then
w.delete
End if
Next
Next
For each f in s.footers
For each w in f.shapes
If left(w.name,18) = "PowerPlusWatermark" then
w.delete
End if
Next
Next
Next

I don't know about inserting them.

--
^K}
"Jay Freedman" wrote in message
...
Hi Kimmie,

To answer this, we're going to have to dig deeper into how this
particular document is set up. If it's what I think it is, the macro
is going to need some fairly major surgery. That's not unusual for a
recorded macro -- I wrote a whole page on the topic
(http://www.word.mvps.org/FAQs/Macros...ordedMacro.htm) and
barely scratched the surface.

The first issue is the watermark vs. the other graphic in the header.
If the other graphic is in-line instead of floating, this won't be a
problem. An easy way to tell the difference is to open the header area
and click once on the graphic. If the "handles" in the corners and
edges of the graphic are black, it's in-line; if they're circles with
white centers, and there's a green handle above the graphic, then it's
floating.

The way this works in a macro is that floating graphics belong to the
Shapes collection, while in-line ones belong to the InlineShapes
collection. They're completely separate groups, so deleting any Shape
(which would be the watermark) won't touch any InlineShape.

If both the watermark and the other graphic are floating Shapes, then
there's a problem, because it's hard for the macro to know which one
is Shapes(1) and which is Shapes(2). It still might be possible, by
checking the value of the Type property of the Shape, but I hope to
avoid the need for that.

The second issue is the first page vs. other pages thing. There are
basically two ways this could happen, and you'll have to tell me which
is correct in your document. Look in the File Page Setup Layout
dialog and tell me whether the "Different odd and even" option is
checked. If not, the other way is if there's a section break between
pages 1 and 2, with headers that are not marked "Same As Previous", so
they can be different. (I'm betting on the odd/even situation.)

Instead of passing these hints back and forth, it might be quicker if
you can email a copy of the document (template?) to me.

--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.

On Fri, 10 Mar 2006 15:16:28 -0800, Kimmie B
wrote:

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 :-)




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

Thanks very much for the suggestion Tony. As you say, I'm wrestling a
strange, complicated beast. I could not get the code below to work, but I
certainly thank you for your time and consideration.

"Tony Jollans" wrote:

Watermarks produced by Format Background Watermark are strange beasts
and I'm not sure you're going to be able to do this at all but something
along these lines might switch them off ...

For each s in activedocument.sections
For each h in s.headers
For each w in h.shapes
If left(w.name,18) = "PowerPlusWatermark" then
w.delete
End if
Next
Next
For each f in s.footers
For each w in f.shapes
If left(w.name,18) = "PowerPlusWatermark" then
w.delete
End if
Next
Next
Next

I don't know about inserting them.

--
^K}
"Jay Freedman" wrote in message
...
Hi Kimmie,

To answer this, we're going to have to dig deeper into how this
particular document is set up. If it's what I think it is, the macro
is going to need some fairly major surgery. That's not unusual for a
recorded macro -- I wrote a whole page on the topic
(http://www.word.mvps.org/FAQs/Macros...ordedMacro.htm) and
barely scratched the surface.

The first issue is the watermark vs. the other graphic in the header.
If the other graphic is in-line instead of floating, this won't be a
problem. An easy way to tell the difference is to open the header area
and click once on the graphic. If the "handles" in the corners and
edges of the graphic are black, it's in-line; if they're circles with
white centers, and there's a green handle above the graphic, then it's
floating.

The way this works in a macro is that floating graphics belong to the
Shapes collection, while in-line ones belong to the InlineShapes
collection. They're completely separate groups, so deleting any Shape
(which would be the watermark) won't touch any InlineShape.

If both the watermark and the other graphic are floating Shapes, then
there's a problem, because it's hard for the macro to know which one
is Shapes(1) and which is Shapes(2). It still might be possible, by
checking the value of the Type property of the Shape, but I hope to
avoid the need for that.

The second issue is the first page vs. other pages thing. There are
basically two ways this could happen, and you'll have to tell me which
is correct in your document. Look in the File Page Setup Layout
dialog and tell me whether the "Different odd and even" option is
checked. If not, the other way is if there's a section break between
pages 1 and 2, with headers that are not marked "Same As Previous", so
they can be different. (I'm betting on the odd/even situation.)

Instead of passing these hints back and forth, it might be quicker if
you can email a copy of the document (template?) to me.

--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.

On Fri, 10 Mar 2006 15:16:28 -0800, Kimmie B
wrote:

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 :-)





  #10   Report Post  
Posted to microsoft.public.word.docmanagement
Tony Jollans
 
Posts: n/a
Default macro produces error message

Sorry, I have tried to understand these things but so far failed and that's
my best shot at the moment

Did it do anything at all?

--
Enjoy,
Tony

"Kimmie B" wrote in message
...
Thanks very much for the suggestion Tony. As you say, I'm wrestling a
strange, complicated beast. I could not get the code below to work, but I
certainly thank you for your time and consideration.

"Tony Jollans" wrote:

Watermarks produced by Format Background Watermark are strange

beasts
and I'm not sure you're going to be able to do this at all but something
along these lines might switch them off ...

For each s in activedocument.sections
For each h in s.headers
For each w in h.shapes
If left(w.name,18) = "PowerPlusWatermark" then
w.delete
End if
Next
Next
For each f in s.footers
For each w in f.shapes
If left(w.name,18) = "PowerPlusWatermark" then
w.delete
End if
Next
Next
Next

I don't know about inserting them.

--
^K}
"Jay Freedman" wrote in message
...
Hi Kimmie,

To answer this, we're going to have to dig deeper into how this
particular document is set up. If it's what I think it is, the macro
is going to need some fairly major surgery. That's not unusual for a
recorded macro -- I wrote a whole page on the topic
(http://www.word.mvps.org/FAQs/Macros...ordedMacro.htm) and
barely scratched the surface.

The first issue is the watermark vs. the other graphic in the header.
If the other graphic is in-line instead of floating, this won't be a
problem. An easy way to tell the difference is to open the header area
and click once on the graphic. If the "handles" in the corners and
edges of the graphic are black, it's in-line; if they're circles with
white centers, and there's a green handle above the graphic, then it's
floating.

The way this works in a macro is that floating graphics belong to the
Shapes collection, while in-line ones belong to the InlineShapes
collection. They're completely separate groups, so deleting any Shape
(which would be the watermark) won't touch any InlineShape.

If both the watermark and the other graphic are floating Shapes, then
there's a problem, because it's hard for the macro to know which one
is Shapes(1) and which is Shapes(2). It still might be possible, by
checking the value of the Type property of the Shape, but I hope to
avoid the need for that.

The second issue is the first page vs. other pages thing. There are
basically two ways this could happen, and you'll have to tell me which
is correct in your document. Look in the File Page Setup Layout
dialog and tell me whether the "Different odd and even" option is
checked. If not, the other way is if there's a section break between
pages 1 and 2, with headers that are not marked "Same As Previous", so
they can be different. (I'm betting on the odd/even situation.)

Instead of passing these hints back and forth, it might be quicker if
you can email a copy of the document (template?) to me.

--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.

On Fri, 10 Mar 2006 15:16:28 -0800, Kimmie B
wrote:

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 :-)









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

Sorry: No it didn't. It produced a syntax compile error.

Tony, I'm terribly impressed with both the level of expertise and the
kindness of strangers who offer help with these off-the-wall questions.
Thank you so much for taking the time to offer a suggestion.

k

"Tony Jollans" wrote:

Sorry, I have tried to understand these things but so far failed and that's
my best shot at the moment

Did it do anything at all?

--
Enjoy,
Tony

"Kimmie B" wrote in message
...
Thanks very much for the suggestion Tony. As you say, I'm wrestling a
strange, complicated beast. I could not get the code below to work, but I
certainly thank you for your time and consideration.

"Tony Jollans" wrote:

Watermarks produced by Format Background Watermark are strange

beasts
and I'm not sure you're going to be able to do this at all but something
along these lines might switch them off ...

For each s in activedocument.sections
For each h in s.headers
For each w in h.shapes
If left(w.name,18) = "PowerPlusWatermark" then
w.delete
End if
Next
Next
For each f in s.footers
For each w in f.shapes
If left(w.name,18) = "PowerPlusWatermark" then
w.delete
End if
Next
Next
Next

I don't know about inserting them.

--
^K}
"Jay Freedman" wrote in message
...
Hi Kimmie,

To answer this, we're going to have to dig deeper into how this
particular document is set up. If it's what I think it is, the macro
is going to need some fairly major surgery. That's not unusual for a
recorded macro -- I wrote a whole page on the topic
(http://www.word.mvps.org/FAQs/Macros...ordedMacro.htm) and
barely scratched the surface.

The first issue is the watermark vs. the other graphic in the header.
If the other graphic is in-line instead of floating, this won't be a
problem. An easy way to tell the difference is to open the header area
and click once on the graphic. If the "handles" in the corners and
edges of the graphic are black, it's in-line; if they're circles with
white centers, and there's a green handle above the graphic, then it's
floating.

The way this works in a macro is that floating graphics belong to the
Shapes collection, while in-line ones belong to the InlineShapes
collection. They're completely separate groups, so deleting any Shape
(which would be the watermark) won't touch any InlineShape.

If both the watermark and the other graphic are floating Shapes, then
there's a problem, because it's hard for the macro to know which one
is Shapes(1) and which is Shapes(2). It still might be possible, by
checking the value of the Type property of the Shape, but I hope to
avoid the need for that.

The second issue is the first page vs. other pages thing. There are
basically two ways this could happen, and you'll have to tell me which
is correct in your document. Look in the File Page Setup Layout
dialog and tell me whether the "Different odd and even" option is
checked. If not, the other way is if there's a section break between
pages 1 and 2, with headers that are not marked "Same As Previous", so
they can be different. (I'm betting on the odd/even situation.)

Instead of passing these hints back and forth, it might be quicker if
you can email a copy of the document (template?) to me.

--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.

On Fri, 10 Mar 2006 15:16:28 -0800, Kimmie B
wrote:

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 :-)








  #12   Report Post  
Posted to microsoft.public.word.docmanagement
Tony Jollans
 
Posts: n/a
Default macro produces error message

Hi Kimmie,

I just typed the code directly into the post so it is possible I made a
mistake. I have just cut and pasted it into a module and found I needed to
declare the variables (because I have Option xplicit). I also found out it's
case sensitive and I got the case worng but this works for me ...

Sub DeleteWatermark()
Dim s As Section
Dim h As HeaderFooter
Dim f As HeaderFooter
Dim w As Shape
For Each s In ActiveDocument.Sections
For Each h In s.Headers
For Each w In h.Shapes
If Left(w.Name, 18) = "PowerPlusWaterMark" Then
w.Delete
End If
Next
Next
For Each f In s.Footers
For Each w In f.Shapes
If Left(w.Name, 18) = "PowerPlusWaterMark" Then
w.Delete
End If
Next
Next
Next
End Sub

If you get any more errors can you post back with what they are?

--
Enjoy,
Tony


"Kimmie B" wrote in message
...
Sorry: No it didn't. It produced a syntax compile error.

Tony, I'm terribly impressed with both the level of expertise and the
kindness of strangers who offer help with these off-the-wall questions.
Thank you so much for taking the time to offer a suggestion.

k

"Tony Jollans" wrote:

Sorry, I have tried to understand these things but so far failed and

that's
my best shot at the moment

Did it do anything at all?

--
Enjoy,
Tony

"Kimmie B" wrote in message
...
Thanks very much for the suggestion Tony. As you say, I'm wrestling a
strange, complicated beast. I could not get the code below to work,

but I
certainly thank you for your time and consideration.

"Tony Jollans" wrote:

Watermarks produced by Format Background Watermark are strange

beasts
and I'm not sure you're going to be able to do this at all but

something
along these lines might switch them off ...

For each s in activedocument.sections
For each h in s.headers
For each w in h.shapes
If left(w.name,18) = "PowerPlusWatermark" then
w.delete
End if
Next
Next
For each f in s.footers
For each w in f.shapes
If left(w.name,18) = "PowerPlusWatermark" then
w.delete
End if
Next
Next
Next

I don't know about inserting them.

--
^K}
"Jay Freedman" wrote in message
...
Hi Kimmie,

To answer this, we're going to have to dig deeper into how this
particular document is set up. If it's what I think it is, the

macro
is going to need some fairly major surgery. That's not unusual for

a
recorded macro -- I wrote a whole page on the topic
(http://www.word.mvps.org/FAQs/Macros...ordedMacro.htm)

and
barely scratched the surface.

The first issue is the watermark vs. the other graphic in the

header.
If the other graphic is in-line instead of floating, this won't be

a
problem. An easy way to tell the difference is to open the header

area
and click once on the graphic. If the "handles" in the corners and
edges of the graphic are black, it's in-line; if they're circles

with
white centers, and there's a green handle above the graphic, then

it's
floating.

The way this works in a macro is that floating graphics belong to

the
Shapes collection, while in-line ones belong to the InlineShapes
collection. They're completely separate groups, so deleting any

Shape
(which would be the watermark) won't touch any InlineShape.

If both the watermark and the other graphic are floating Shapes,

then
there's a problem, because it's hard for the macro to know which

one
is Shapes(1) and which is Shapes(2). It still might be possible,

by
checking the value of the Type property of the Shape, but I hope

to
avoid the need for that.

The second issue is the first page vs. other pages thing. There

are
basically two ways this could happen, and you'll have to tell me

which
is correct in your document. Look in the File Page Setup

Layout
dialog and tell me whether the "Different odd and even" option is
checked. If not, the other way is if there's a section break

between
pages 1 and 2, with headers that are not marked "Same As

Previous", so
they can be different. (I'm betting on the odd/even situation.)

Instead of passing these hints back and forth, it might be quicker

if
you can email a copy of the document (template?) to me.

--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.

On Fri, 10 Mar 2006 15:16:28 -0800, Kimmie B
wrote:

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 :-)










Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Table in a Form HiDbLevel Tables 12 February 27th 06 01:59 PM
Macro Button Won't Stay on Toolbar caleb Microsoft Word Help 2 June 14th 05 11:59 PM
Possible bug when recording a Word Macro Raven95 Microsoft Word Help 4 April 30th 05 09:49 PM
Running document macro from server Intravler New Users 0 March 4th 05 05:33 AM
2000 to 2002 macro and "Could not open macro storage" Art Farrell Mailmerge 1 December 6th 04 01:40 PM


All times are GMT +1. The time now is 02:16 PM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"