Home |
Search |
Today's Posts |
|
#1
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
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
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
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
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
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
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
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
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
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
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
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
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
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 :-) |
Reply |
Thread Tools | |
Display Modes | |
|
|
Similar Threads | ||||
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 |