On 11/5/05, John Machin <[EMAIL PROTECTED]> wrote:
It was giving me errors when I tried to use the constants so I stopped using them. A future question perhaps...
That is correct.
This doesn't bother me much to write out numbers.
What do you mean by inspect?
Well I run my code, word opens the file, other changes happen, but the watermark doesn't dissapear.
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 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)
_______________________________________________ Python-win32 mailing list Python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32