[python-win32] Pythonwin - Word automation - Removing watermark not working

Gregory Piñero gregpinero at gmail.com
Sat Nov 5 21:15:40 CET 2005


See below:

On 11/5/05, John Machin <sjmachin at lexicon.net> wrote:
>
> Gregory Piñero wrote:
>
> >
> > Would anyone happen to know why this my function removewatermark() in
> > this code isn't working? I copied it from a Word macro I recorded and
> > it did work when I recorded the macro. When I run it the watermark
> > doesn't go away.
> >
> > I've also attached the code in case the formatting gets messed up from
> > the email.
> >
> >
> > <code>
> > import sys
> > import os
> > from win32com.client import gencache, constants
>
> Idle curiosity: why import constants but not use it?


It was giving me errors when I tried to use the constants so I stopped using
them. A future question perhaps...

> WORD='Word.Application'
> > False,True=0,-1
> >
> > class Word:
> > def __init__(self):
> > self.app=gencache.EnsureDispatch(WORD)
> > self.app.Visible = 1
> > self.app.DisplayAlerts = 0
>
> What does this do? Suppress any warnings?


That is correct.

> def open(self,doc):
> > self.app.Documents.Open(FileName=doc)
> > def removewatermark(self):
> > self.app.ActiveDocument.Sections(1).Range.Select()
> > self.app.ActiveWindow.ActivePane.View.SeekView = 9 #
> > wdSeekCurrentPageHeader
>
> ... the cause of the "idle curiosity" question.


This doesn't bother me much to write out numbers.

>
> > self.app.Selection.HeaderFooter.Shapes
> ("PowerPlusWaterMarkObject1").Select()
>
> Have you tried inspecting self.app.Selection before and after the
> attempt to .Delete() it?


What do you mean by inspect?

> self.app.Selection.Delete()
> > self.app.ActiveWindow.ActivePane.View.SeekView = 0
> > #wdSeekMainDocument
> > </code>
> >
>
> How do you know it didn't work?


Well I run my code, word opens the file, other changes happen, but the
watermark doesn't dissapear.

Your class and its methods don't have any problems that I can see --
> but it's early here and I'm not quite awake. Is it possible for you to
> show us the few lines of code that you actually used to test this? You
> know, something like:
>
> wc = Word()
> wc.open("myfile.doc")
> wc.removewatermark()
> # then what?


Something like this:

word=Word()
word.open("myfile.doc")
word.replace("[Sender]","Bill Brown") #replace a word
word.removewatermark()
word.printdoc(numcopies=3) #prints, works fine
word.close() #closes doc
word.quit() #shuts down word

I only included the relevant parts of this class. So you see some methods
above that aren't in my class. I guess I should have included the whole
class, sorry. Now I can't get back to that code until Tuesday :-(
But all of the methods work fine except for removewatermark.



--
Gregory Piñero
Chief Innovation Officer
Blended Technologies
(www.blendedtechnologies.com <http://www.blendedtechnologies.com>)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/python-win32/attachments/20051105/82a623a9/attachment.htm


More information about the Python-win32 mailing list