update a word-bookmark with the win32.com extension
Steve Coates
steve.coates at smiths-aerospace.com
Mon Nov 24 02:59:22 EST 2003
docelm at web.de (Christian Lehmann) wrote in message news:<48bafd6d.0311180542.5f7582ea at posting.google.com>...
> Hello,
>
> I want to update a bookmark in a word file.
> My code looks like this:
>
> def UpdateBookmark(BookmarkToUpdate, TextToUse):
> FieldRange = Document.Bookmarks(BookmarkToUpdate).Range
> FieldRange.Text = TextToUse # error message
> ActiveDocument.Bookmarks.Add(BookmarkToUpdate,FieldRange)
>
>
> UpdateBookmark ("Bookmarkname","newString")
>
>
> when i assign the new string an error message occurs.
> I m using Office XP...
>
> Thanks
> Christian
I've used the following in Word97. It isn't very pretty, but
it does work:-
def UpdateBookmark(App, Doc, Bookmark, Value):
Doc.Bookmarks(Bookmark).Select()
s = App.Selection
s.Cut()
s.InsertBefore(Value)
Doc.Bookmarks.Add(Bookmark)
Steve Coates
Also somewhere in the West of England
More information about the Python-list
mailing list