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

John Machin sjmachin at lexicon.net
Sat Nov 5 20:09:16 CET 2005


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?

> 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?

>     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.

>         
> self.app.Selection.HeaderFooter.Shapes("PowerPlusWaterMarkObject1").Select()

Have you tried inspecting self.app.Selection before and after the 
attempt to .Delete() it?

>         self.app.Selection.Delete()
>         self.app.ActiveWindow.ActivePane.View.SeekView = 0 
> #wdSeekMainDocument
> </code>
> 

How do you know it didn't work?

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?

Cheers,
John



More information about the Python-win32 mailing list