update a word-bookmark with the win32.com extension

Discussion in 'Python' started by Christian Lehmann, Nov 18, 2003.

  1. 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
    Christian Lehmann, Nov 18, 2003
    #1
    1. Advertising

  2. Christian Lehmann

    Bob Gailer Guest

    At 06:42 AM 11/18/2003, Christian Lehmann wrote:

    >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

    303 442 2625


    ---
    Outgoing mail is certified Virus Free.
    Checked by AVG anti-virus system (http://www.grisoft.com).
    Version: 6.0.538 / Virus Database: 333 - Release Date: 11/10/2003
    Bob Gailer, Nov 22, 2003
    #2
    1. Advertising

  3. Christian Lehmann

    Steve Coates Guest

    (Christian Lehmann) wrote in message news:<>...
    > 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
    Steve Coates, Nov 24, 2003
    #3
  4. >
    > 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)
    Christian Lehmann, Nov 24, 2003
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Dan M

    Move to bookmark after postback

    Dan M, Jul 2, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    447
    Steve C. Orr, MCSD
    Jul 2, 2003
  2. Craig Deelsnyder

    Re: Accessing bookmark in a word document

    Craig Deelsnyder, Jun 26, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    413
    Craig Deelsnyder
    Jun 26, 2004
  3. Java and Swing
    Replies:
    1
    Views:
    674
    Chris Lambacher
    Oct 24, 2005
  4. Tim Golden
    Replies:
    0
    Views:
    441
    Tim Golden
    Oct 21, 2005
  5. deepakp
    Replies:
    1
    Views:
    685
    A. Sinan Unur
    Mar 3, 2006
Loading...

Share This Page