file open problem: setting bookmark to range of content control

K

kozaw

Hi,

How do I know the limitation on nesting level of content controls.

I created a word 2007 template including multiple content controls,
some of which are nested (just one level.)
As I want to reuse these phrases in latter part of document, I set the
bookmarks on exact location of my desired content controls (also
obeying the bookmark naming rules).

As far as this no problem occurred.
When the document was reopened (yes! as a new doc or itself), word
says following.
"THE OFFICE OPEN XML FILE <FILE NAME> CANNOT BE OPENED BECAUSE THERE
ARE PROBLEMS WITH THE CONTENTS.
Details: Unspecified error
Location: part:/word/document.xml, line:2, Column:1548"

And WORD ask me to repair and make a newly recovered file for me. I
start to squeeze the problematic area by narrowing the range of
document each time reopening it. just line # and column # are varied
in error dialog boxes.

Finally I found the problem. i.e., setting Bookmark to exact range of
single (unnested) content control is causing problem.
My only workaround is deleting all bookmarks by macro before closing
the document, and re-setting bookmarks to desired content controls on
event of open. But it cost time, and very confusing.

Please help me to solve the problem.
NB: I created the problem faced dotx file with only 3 words. And would
like to present to WORD MVPs for assistance in problem solving. Is it
a known bug?

Brgds,
Ko Zaw
 
C

Cindy M.

Hi Kozaw,

Can you explain please why you need to use bookmarks with the content
controls

AND

at what position the bookmarks are in relation to the ContentControls
(around a control, in a control, around text within a control...)

Word is continually destroying/recreating ContentControls and I'm
guessing what you're seeing has something to do with that (Word getting
it wrong). I need to be able to reproduce the problem in order to make
any suggestions, and to forward it to the dev team.
How do I know the limitation on nesting level of content controls.

I created a word 2007 template including multiple content controls,
some of which are nested (just one level.)
As I want to reuse these phrases in latter part of document, I set the
bookmarks on exact location of my desired content controls (also
obeying the bookmark naming rules).

As far as this no problem occurred.
When the document was reopened (yes! as a new doc or itself), word
says following.
"THE OFFICE OPEN XML FILE <FILE NAME> CANNOT BE OPENED BECAUSE THERE
ARE PROBLEMS WITH THE CONTENTS.
Details: Unspecified error
Location: part:/word/document.xml, line:2, Column:1548"

And WORD ask me to repair and make a newly recovered file for me. I
start to squeeze the problematic area by narrowing the range of
document each time reopening it. just line # and column # are varied
in error dialog boxes.

Finally I found the problem. i.e., setting Bookmark to exact range of
single (unnested) content control is causing problem.
My only workaround is deleting all bookmarks by macro before closing
the document, and re-setting bookmarks to desired content controls on
event of open. But it cost time, and very confusing.

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 :)
 
K

kozaw

Hi Kozaw,

Can you explain please why you need to use bookmarks with the content
controls

AND

at what position the bookmarks are in relation to the ContentControls
(around a control, in a control, around text within a control...)

Word is continually destroying/recreating ContentControls and I'm
guessing what you're seeing has something to do with that (Word getting
it wrong). I need to be able to reproduce the problem in order to make
any suggestions, and to forward it to the dev team.












Cindy Meister
INTER-Solutions, Switzerlandhttp://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 :)

Hello! Cindy,

Thanks for your reply.

Let me explain.
1. Need to use bookmarks with the content controls?
I have long document for routine works. Each document has multiple
sections. Later Sections have the fields which refer to bookmarks on
1st Section. (NB: Range of Each Bookmark may have table, that why I
cann't simply use mailmerge features.) The best is I can refer
directly to the range of content controls for later sections, but I
can't understand the way, and I decided to use Bookmarks.
The reason of using contents controls is:- a) Values of some
bookmarks have fix value these must be chosen from my Entry List. b).
For many bookmarks, Users are keen to enter the values outside the
range of bookmark, if bookmark marking are hidden by some reason.

2. Position the bookmarks in relation to the ContentControls?
Like said above, they have exact range with each contentcontrol. For
example, I use the title of contentcontrol (excluding which are start
with numbers, character "x", and must be continuous) to as name of
that bookmark with following code.

Sub kzCreatBMsFromContentTrls()
On Error GoTo er
Debug.Print Time & " " & "kzCreatBMsFromContentTrls"
Application.StatusBar = "Creating Bookmarks from Content Controls.."
' Del all Bookmarks in activedocument
'
' I delete all bookmarks here kzDelAllBMs
'
Dim MyContentCtrl As ContentControl
Dim MyRange As Range
Dim MyBMName As String
' checking number of content controls
If ActiveDocument.ContentControls.Count > 0 Then ' if
contentcontrol(s) exist then try to set bookmark.

For Each MyContentCtrl In ActiveDocument.ContentControls '
Iterate through each element.
MyBMName = MyContentCtrl.Title 'First record
ContentCtrl.Title to set as Bookmark Name.

' MyBMName = StrConv(MyBMName$, vbNarrow) 'I closed be'cos
invalid procedure err occur!
If Left(LCase(MyBMName), 1) = "x" Then
' Debug.Print Time & " " & MyBMName & " - skipped
Bookmarking" 'just for checking
GoTo GotoNextContentCtrl

ElseIf Len(MyContentCtrl.Range.Text) = 0 Or _
Left(LCase(MyContentCtrl.Range.Text), 4) = "none" Or _
IsNull(MyContentCtrl.Range.Text) Or _
InStr(1, MyContentCtrl.Range.Text, "Click", vbTextCompare) > 0
Or _
InStr(1, MyContentCtrl.Range.Text, "Choose", vbTextCompare) >
0 Then

Set MyRange = MyContentCtrl.Range
MyRange.Collapse Direction:=wdCollapseStart
ActiveDocument.Bookmarks.Add MyBMName, MyRange

' for all content controls otherthan above
ElseIf Left(LCase(MyBMName), 1) <> "x" Then
' Debug.Print Time & " " & MyBMName & " - Bookmark CREATED.."
'just for checking
Set MyRange = MyContentCtrl.Range
ActiveDocument.Bookmarks.Add MyBMName, MyRange
Set MyRange = Nothing

End If
GotoNextContentCtrl:
Next MyContentCtrl
End If


Application.StatusBar = "Finished.. Creating Bookmarks from Content
Controls.."
Exit sub
er:
MsgBox "Error found: kzCreatBMsFromContentTrls: " & MyBMName &
vbCrLf & Err.Description
End sub

I really appreciate your reply and help me to overcome the problems.
I noticed later that when the recovered document was opened, just
right side of content control mark was jumped-out of bookmark range. I
checked again there were exact range of bookmark and content control
before I closed the document, but when reopen again the problem
occurred.

For the time being, I workaround this problem with deleting All
Bookmarks in before save event and before close event.
That's why I thought is it a bug..
Ko Zaw
 
C

Cindy M.

Hi Kozaw,
1. Need to use bookmarks with the content controls?
I have long document for routine works. Each document has multiple
sections. Later Sections have the fields which refer to bookmarks on
1st Section. (NB: Range of Each Bookmark may have table, that why I
cann't simply use mailmerge features.) The best is I can refer
directly to the range of content controls for later sections
OK, we're hitting a bit of a language barrier, here. If I understand
you correctly, you want to display information from a Content Control
at a later point in the document? Using REF fields?

Or do you mean something else?

The ContentControls are designed so that you shouldn't need to
bookmark them. But in order to make any suggestions, I do have to
understand exactly how you want to use them.

Another thing: can your repeat the crash you're getting by assigning
the bookmark to Content Controls using Insert/Bookmark? Or does it
happen only when using your code?

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 :)
 
K

kozaw

Hi Kozaw,


OK, we're hitting a bit of a language barrier, here. If I understand
you correctly, you want to display information from a Content Control
at a later point in the document? Using REF fields?

Or do you mean something else?

The ContentControls are designed so that you shouldn't need to
bookmark them. But in order to make any suggestions, I do have to
understand exactly how you want to use them.

Another thing: can your repeat the crash you're getting by assigning
the bookmark to Content Controls using Insert/Bookmark? Or does it
happen only when using your code?

Cindy Meister
INTER-Solutions, Switzerlandhttp://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 :)

Hello Cindy Meister,

Thanks again. You are the one who attend my problem.
Yes. I want to display information of content control in later part of
same document.
Did you read my last post. I already told about I bookmark them and
then made ref fields.

In order to make bookmark on exact range of each content control,
insert - field is a labour work and don't invloved coding, and don't
reliable when user changed the information of content control.
Therefore, I'm doing bookmarking with above code. You can check the
code. I've simulated crashed file dotx, a simple file about 40kb. I
can send it to you, if you want to check at your end.

I somehow overcome by deleting all bookmarks on before close event.
Thats why invloved coding, in order to re bookmark them.

Now, I want to know how can I reuse information of content control on
later part of document instead of bookmarking them.

Trust you will find out the problem.
Ko Zaw
 
C

Cindy M.

Hi Kozaw,
Now, I want to know how can I reuse information of content control on
later part of document instead of bookmarking them.
Thanks for the confirmation :)

This can be done by setting up a CustomPart in the document with XML
that corresponds to the content controls, then mapping the content
controls to the XML.

When you've done this, you can insert as many ContentControls with the
SAME TITLE as you require. Everything with the same title (which is
mapped to a specific XML tag) will show the same information (and also
write to the XML file if editing is allowed).

Here's a link that shows how this is done by modifying the file's XML
directly:
http://blogs.msdn.com/modonovan/archive/2006/05/23/604704.aspx

This link describes how to do the same using the object model (macros,
for example)
http://msdn2.microsoft.com/en-us/library/ms406053.aspx

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 :)
 

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