Home |
Search |
Today's Posts |
#12
![]()
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
![]()
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 :-) |
Thread Tools | |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Table in a Form | Tables | |||
Macro Button Won't Stay on Toolbar | Microsoft Word Help | |||
Possible bug when recording a Word Macro | Microsoft Word Help | |||
Running document macro from server | New Users | |||
2000 to 2002 macro and "Could not open macro storage" | Mailmerge |