Word CaptionLabels

P

Peter Karlström

Hi

I have developed a COM Addin for Word XP and 2003 which involves customized
CaptionLabels, for example Picture and Graph.
It works fine to add them to the document in the format my customer wants.
But when I try to implement the translation feature which translates certain
parts of the document from Swedish to English and vice verca I got problems.

I can't seem to find the CaptionLabel "collection" which I'm using in the
document.
Looping thru the collection only presents me with the standard Captionlabels
Figure, Table and Formula.

How can I find my customized Captionlabels to be able to translate them?

Thanks in advance
 
J

Jialiang Ge [MSFT]

Hello Peter,

From your post, my understanding on this issue is: you wonder why Word does
not list the custom caption labels when looping through the CaptionLabel
collection, and how to work-around it. If I'm off base, please feel free to
let me know.

First of all, please let me explain why the custom caption labels are not
listed in the Application.CaptionLabels collection:
According to the KB article http://support.microsoft.com/kb/114281, the
custom caption labels are stored in the Normal.dot template, which is an
application level setting, rather than a document level thing. If the Word
document is moved to another machine whose Normal.dot does not define the
custom caption labels, Word will not be aware of them when you loop through
Application.CaptionLabels collection. In my best guess, your add-in does
not find the correct custom caption list because the document is not on the
machine that defines these labels.

In order to work-around it, we can rebuild the custom caption label list by
iterating the Fields in the document. According to another KB article
http://support.microsoft.com/kb/195486, The field of caption labels is in
the form of
Label Name {SEQ Identifier [Switches]}
For instance, if you mouse-right-click on a Table caption label in a word
document, something like "Table {SEQ Table \* ARABIC}" will be shown.
Therefore, we can iterate all the fields with Word object model:
Document.Fields, and see if a field fits the form "{SEQ @@@ \* ¡­}" where
@@@ is the name of the caption label. If it fits, and @@@ is not the system
built-in captions, we can say it is a custom caption label. What we need to
do next is to translate @@@ to the target language, then add it to
Application.CaptionLabels collection.

Please have a try and let me know if it works for you.

Regards,
Jialiang Ge ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
For MSDN subscribers whose posts are left unanswered, please check this
document: http://blogs.msdn.com/msdnts/pages/postingAlias.aspx

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications. If you are using Outlook Express/Windows Mail, please make sure
you clear the check box "Tools/Options/Read: Get 300 headers at a time" to
see your reply promptly.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
P

Peter Karlström

Hi Jialiang Ge

Thank you for your quick reply.

The code for adding a CaptionLabel to the document in my COM Addin is as
follows:
(wrdApp is the Word Application Object in the COM Addin
Variable refText in the code is for instance "Picture".)

wrdApp.CaptionLabels.Add Name:=refText
wrdApp.Selection.InsertCaption Label:=refText, TitleAutoText:="", _
Title:="", Position:=wdCaptionPositionBelow
With CaptionLabels(refText)
.NumberStyle = wdCaptionNumberStyleArabic
.IncludeChapterNumber = True
.ChapterStyleLevel = 1
.Separator = wdSeparatorHyphen
End With

This shows like Picture 1-1 for the 1:st picture in chapter 1 in the document
and results in fieldcodes something like the one below:
Picture { STYLEREF 1 \s }-{ SEQ Picture \* ARABIC \s 1 }

The STYLEREF- and SEQ-fields are two separate field in the fields
collection.

For the CaptionLabels and the Reference-TOC to be correct I have to change
both the inline and the outline Picture to Bild (which is Swedish for
Picture) when I
translate it.

Can I assume that the pair of fields is in correct order when I loop thru
the fields collection?

Thanks in advance

--
Peter Karlström
Midrange AB
Sweden


Jialiang Ge said:
Hello Peter,

From your post, my understanding on this issue is: you wonder why Word does
not list the custom caption labels when looping through the CaptionLabel
collection, and how to work-around it. If I'm off base, please feel free to
let me know.

First of all, please let me explain why the custom caption labels are not
listed in the Application.CaptionLabels collection:
According to the KB article http://support.microsoft.com/kb/114281, the
custom caption labels are stored in the Normal.dot template, which is an
application level setting, rather than a document level thing. If the Word
document is moved to another machine whose Normal.dot does not define the
custom caption labels, Word will not be aware of them when you loop through
Application.CaptionLabels collection. In my best guess, your add-in does
not find the correct custom caption list because the document is not on the
machine that defines these labels.

In order to work-around it, we can rebuild the custom caption label list by
iterating the Fields in the document. According to another KB article
http://support.microsoft.com/kb/195486, The field of caption labels is in
the form of
Label Name {SEQ Identifier [Switches]}
For instance, if you mouse-right-click on a Table caption label in a word
document, something like "Table {SEQ Table \* ARABIC}" will be shown.
Therefore, we can iterate all the fields with Word object model:
Document.Fields, and see if a field fits the form "{SEQ @@@ \* ¡­}" where
@@@ is the name of the caption label. If it fits, and @@@ is not the system
built-in captions, we can say it is a custom caption label. What we need to
do next is to translate @@@ to the target language, then add it to
Application.CaptionLabels collection.

Please have a try and let me know if it works for you.

Regards,
Jialiang Ge ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
For MSDN subscribers whose posts are left unanswered, please check this
document: http://blogs.msdn.com/msdnts/pages/postingAlias.aspx

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications. If you are using Outlook Express/Windows Mail, please make sure
you clear the check box "Tools/Options/Read: Get 300 headers at a time" to
see your reply promptly.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
J

Jialiang Ge [MSFT]

Hello Peter,

I think it will be safer if we query {SEQ} fields only. The STYLEREF field
shows because of ".ChapterStyleLevel = 1" in the code, so STYLEREF is not
necessarily there. We need to query SEQ fields and get the caption label
name (e.g Picture) inside it, then look for the label (e.g. Picture)
outside the field by finding the word forward from the SEQ.

Regards,
Jialiang Ge ([email protected], remove 'online.')
Microsoft Online Community Support

=================================================
When responding to posts, please "Reply to Group" via your newsreader
so that others may learn and benefit from your issue.
=================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
P

Peter Karlström

Hi Jialiang Ge

You got me on the right track with the fields-collection...

Maybe you didn't understand by my code and the resulting text and
field-code, that it's not the field-code itself that I want to translate,
it's the Label which is shown in the document.
I use the fields collection to find the respective SEQ-fields, and since I
always know the length of the old Label, I select it from the current row and
replace it with the proper translation.

The table of figures (which also is used) are automatically updated with the
following:
For each tof in ActiveDocument.TableOfFigures
tof.Update
Next

Again, thank you for your excellent support.

Regards
 
J

Jialiang Ge [MSFT]

Hello Peter,

Yes. Maybe I misunderstood part of the codes because I did not have a clear
overall picture of your add-in project. If you have any other questions or
concerns, please do feel free to let me know. I will do my best to help.

Regards,
Jialiang Ge ([email protected], remove 'online.')
Microsoft Online Community Support

=================================================
When responding to posts, please "Reply to Group" via your newsreader
so that others may learn and benefit from your issue.
=================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 

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