Bookmarks disappearing still a problem

P

Peter Karlström

Hi

In a previous post I mentioned a problem I had with disappearing bookmarks.
I then realized that my placing of the bookmarks start- and end-positions in
the document was wrong.
I made a lot of changes according to Cindy Meisters tip and when I study the
XML-code in the document it now looks fine.
But the problem still persists. If I open the document and save it, some of
the bookmarks is still deleted by Word.

The XML-code of the footer1.xml file for the bookmarks looks like this:

<w:bookmarkStart w:id="6" w:name="plc_112" />
<w:bookmarkEnd w:id="6" />
</w:p>
</w:tc>
<w:bookmarkStart w:id="7" w:name="plc_122" />
<w:bookmarkEnd w:id="7" />

What could be wrong now?

Thanks in advance
 
C

Cindy M.

Hi Peter,

It would be helpful if you would continue a conversation, rather than starting
a new thread. If you start a new thread, you have to remember to include all
relevant information, such as the version of Word and anything else mentioned
in an earlier discussion. Or, at least, a link to that discussion.

You also need to give more specifics about the problem: "some of the bookmarks
are still deleted by Word" isn't enough information.

Is there anything the bookmarks that are getting lost have in common? For
instance, are they in the same place, or kind of place, in the document?

What kinds of things are you assigning bookmarks to? Are any of these locations
dynamic links, or even inside dynamic links? (For example, is there a linked
Excel table, in Word table format, you're putting bookmarks in?)
N a previous post I mentioned a problem I had with disappearing bookmarks.
I then realized that my placing of the bookmarks start- and end-positions in
the document was wrong.
I made a lot of changes according to Cindy Meisters tip and when I study the
XML-code in the document it now looks fine.
But the problem still persists. If I open the document and save it, some of
the bookmarks is still deleted by Word.

The XML-code of the footer1.xml file for the bookmarks looks like this:

<w:bookmarkStart w:id="6" w:name="plc_112" />
<w:bookmarkEnd w:id="6" />
</w:p>
</w:tc>
<w:bookmarkStart w:id="7" w:name="plc_122" />
<w:bookmarkEnd w:id="7" />

What could be wrong now?

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or reply
in the newsgroup and not by e-mail :)
 
P

Peter Karlström

Hi Cindy

OK, here is all the background:

Step 1:
I use an AutoText entry consisting of a 2 by 2 table. Each cell in the table
holds a unique bookmark for positioning.
When I create the document, the Autotext entry is inserted in the
PrimaryPageFooter. The XML of the table is checked and the bookmark is placed
within the tc-tags. Se below:
The problem bookmark is named plc_122.
+++++ START OF XML ++++
- <w:tc>
- <w:tcPr>
<w:tcW w:w="5148" w:type="dxa" />
<w:vAlign w:val="bottom" />
</w:tcPr>
- <w:p w:rsidR="00AF1F1E" w:rsidRPr="00F24C49" w:rsidRDefault="00AF1F1E">
- <w:pPr>
- <w:rPr>
<w:sz w:val="18" />
<w:szCs w:val="18" />
</w:rPr>
</w:pPr>
<w:bookmarkStart w:id="4" w:name="plc_112" />
<w:bookmarkEnd w:id="4" />
</w:p>
</w:tc>
- <w:tc>
- <w:tcPr>
<w:tcW w:w="4932" w:type="dxa" />
<w:vAlign w:val="bottom" />
</w:tcPr>
- <w:p w:rsidR="00AF1F1E" w:rsidRPr="00F24C49" w:rsidRDefault="00AF1F1E">
- <w:pPr>
- <w:rPr>
<w:sz w:val="18" />
<w:szCs w:val="18" />
</w:rPr>
</w:pPr>
<w:bookmarkStart w:id="5" w:name="plc_122" />
<w:bookmarkEnd w:id="5" />
</w:p>
</w:tc>
+++++ END OF XML ++++

Step 2:
The specific part that selects this bookmark, adds a Field and recreates the
bookmark is shown below:
When starting, the bookmark plc_122 is placed in the left of the cell and
consists of 0 characters, and tmpBM is set to "plc_122".
rs2("Datacell") is a CustomDocumentProperty.

++++++ START OF CODE ++++++++
Dim rngBM As Word.Range
Dim fldBM As Word.Field

Set rngBM = tDoc.Bookmarks(tmpBM).Range
rngBM.Font.Name = "Arial"
rngBM.Font.Size = 9
rngBM.Font.Italic = False
rngBM.Font.Bold = True
Set fldBM = rngBM.Fields.Add(rngBM, wdFieldEmpty, "DOCPROPERTY " &
Trim(rs2("Datacell")) & " ", True)
fldBM.ShowCodes = False
tDoc.ActiveWindow.Selection.HomeKey
tDoc.Bookmarks.Add tmpBM, tDoc.ActiveWindow.Selection.Range
Set rngBM = Nothing
Set fldBM = Nothing
++++++ END OF CODE ++++++++

Followup:
When I check the XML of the resulting documents footer1.xml file the
bookmark is placed between two cells. Se below:
++++++ START OF XML +++++
- <w:tc>
- <w:tcPr>
<w:tcW w:w="5148" w:type="dxa" />
<w:vAlign w:val="bottom" />
</w:tcPr>
- <w:p w:rsidR="00C11729" w:rsidRPr="00C11729" w:rsidRDefault="00C11729"
w:rsidP="0045599E">
- <w:pPr>
<w:pStyle w:val="Sidfot" />
<w:spacing w:after="0" />
- <w:rPr>
<w:rFonts w:ascii="Arial" w:hAnsi="Arial" w:cs="Arial" />
<w:sz w:val="16" />
</w:rPr>
</w:pPr>
<w:bookmarkStart w:id="6" w:name="plc_112" />
<w:bookmarkEnd w:id="6" />
</w:p>
</w:tc>
<w:bookmarkStart w:id="7" w:name="plc_122" />
<w:bookmarkEnd w:id="7" />
- <w:tc>
++++++ END OF XML +++++

I can't figure out how this can place the bookmark between the cells in the
table.

Hope this clearify the details of the posting.
 
P

Peter Karlström

It seems I can't add attachments using Outlook Express.

I'll mail it to you Cindy.

Best Regards
 
P

Peter Karlström

Hi

More information has come from Jialiang Ge on Microsoft Online support.

We have discovered that it is the following code that corrupts the bookmark:
Set fldBM = rngBM.Fields.Add(rngBM, wdFieldEmpty.......
When the bookmark is located as a placeholder bookmark and you select it and
add a field, the bookmark is "pushed" out of the cell.
The error can be avoided by first add a space after the bookmark, but that
solution, which will have a space in front of every field in the document, is
not accepted by my customer.

So if anybody has an idea of how to solve this I would much appreciate it.

Thanks in advance
 
C

Cindy M.

Hi Peter,
I can't figure out how this can place the bookmark between the cells in the
table.
Um. If I interpet this literally, what you want to do is not allowed. A
bookmark may not be "between" cells. It must be within a cell.

I'm wondering if the problem is this:

tDoc.ActiveWindow.Selection.HomeKey
tDoc.Bookmarks.Add tmpBM, tDoc.ActiveWindow.Selection.Range

I can see why what I gave you doesn't work: the range won't extend to include
the field code. Try something more like this

Dim rng As Word.Range
Dim fld As Word.Field

Set rng = tDoc.Bookmarks("cell4").Range
Set fld = tDoc.Fields.Add(rng, wdFieldEmpty, "DocProperty Title", False)
rng.End = fld.Result.End
tDoc.Bookmarks.Add "cell4", rng


Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or
reply in the newsgroup and not by e-mail :)
 
P

Peter Karlström

Hi Cindy

Thanks for your reply and your suggestion.

Unfortunately this makes the bookmark surround the field, and that is not
the requested behavior.
My customers documents can sometimes be rather complex and the application
is originally built to use placeholder bookmarks for some of the information.
This part of my customer-project is of a migrating kind from Office XP/2003
to Office 2007. So you can understand that recoding as little as possible is
essential.

The goal for this part of the application is to find the placeholder
bookmark, add the field and let the bookmark remain in its original position,
as a placeholder bookmark rather than a surroundning bookmark.

I will also comunicate this error to Microsoft Support and to Jialiang Ge on
Microsoft Online Support. Any news on the subject will be submitted to this
newsgroup post.

Best Regards
 
P

Peter Karlström

Here is the conclusion to this error.

The dissappearing bookmarks is caused by a bug in Word 2007. The error
occurs when a field is placed directly after a tablecell bookmark.
The bookmark is "pushed" out of the cell by the XML parser when the document
is saved. After a save/close and reopen of the document, the bookmark is
deleted.

The bug will hopefully be fixed in SP2, but Microsoft gave no guarantees on
that.

Regards
 
C

Cindy M.

Hi Peter,
We have discovered that it is the following code that corrupts the bookmark:
Set fldBM = rngBM.Fields.Add(rngBM, wdFieldEmpty.......
When the bookmark is located as a placeholder bookmark and you select it and
add a field, the bookmark is "pushed" out of the cell.
The error can be avoided by first add a space after the bookmark, but that
solution, which will have a space in front of every field in the document, is
not accepted by my customer.
Interesting - and unexpected.

What I'd try is formatting that space very, very small (1 pt). I think the
client will not notice that?

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or reply
in the newsgroup and not by e-mail :)
 
P

Peter Karlström

Hi Cindy

There is a bugfix on it's way but it is not likely to be delivered until
later this year.

In the meantime, the following will work:

Activedocument.Bookmarks("plc_11").Select
Selection.TypeText Chr(31)
Activedocument.Fields.Add Selection.Range, wdFieldEmpty, " DOCPROPERTY
Company", True

This "softHyphen" protects the bookmark from being moved of of the cell by
the XML parser.

Best Regards
 

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

Top