update a word-bookmark with the win32.com extension

C

Christian Lehmann

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
 
B

Bob Gailer

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.

Please include the error message in your postings.

Bob Gailer
(e-mail address removed)
303 442 2625
 
S

Steve Coates

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
 
C

Christian Lehmann

Please include the error message in your postings.

Here is the error messages:

Traceback (most recent call last):
File "D:\DataFinder\python\readFormFields.py", line 95, in ?
date = searchField("date")
File "D:\DataFinder\python\readFormFields.py", line 70, in searchField
field.Text = "Hell"
File "C:\Python\lib\site-packages\win32com\client\__init__.py", line 377, in _
_setattr__
apply(self._oleobj_.Invoke, args + (value,) + defArgs)
pywintypes.com_error: (-2147352567, 'exception error occured.', (0, 'Microsof
t Word', 'The area can´t be deleted', 'C:\\Programs\\Microsoft
Office\\Office10\\1031\\wdmain10.chm', 25508, -2146822260), None)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top