Problem with GetCrossReferenceItems/InsertCrossReference

J

Jezebel

I have some VB code that automatically inserts cross-references:

1. Retrieve the list of headings --

pMyheadings = WordDoc.GetCrossReferenceItems(wdRefTypeHeading)

2. Select one heading from the array (= pIndex)

3. Insert the selected cross-reference --

WordDoc.InsertCrossReference ReferenceType:=wdRefTypeHeading, _
ReferenceKind:=wdContentText, _
ReferenceItem:=pIndex, _
InsertAsHyperlink:=pHyperlink, _
IncludePosition:=False


Most of the time this works as expected; but I have a couple of documents in
which it behaves strangely -- there are some Index values on which the
Insert statement fails (with the brilliantly helpful message "Command
failed") -- and subsequent index values return the wrong heading. Eg, Index
= 12 fails; but using Index = 13 inserts a cross-reference to the 12th item
in the GetCrossReferenceItems() array.

Using the manual Insert > Cross-Reference function works fine.

The only features of the documents on which this fails that are at all
unusual are a) rather longer than normal, and b) some non-built-in styles
with outline levels 1 and 3.

Any thoughts or prior convictions?
 
W

Word Heretic

G'day "Jezebel" <[email protected]>,

I do NOT trust Word's auto-ref feature at all. I have seen it break
down many times. Thus I build headings lists by searching through
..paras for .outlinelevels or use FnR on the default styles.


Steve Hudson - Word Heretic
Want a hyperlinked index? S/W R&D? See WordHeretic.com

steve from wordheretic.com (Email replies require payment)


Jezebel reckoned:
 
J

Jezebel

Thanks for the thought. Do you have some clever technique to determine when
the heading list needs to be rebuilt? In this case the document is too long
to re-construct the list every time I want to add a cross-reference; but the
list of headings might well have changed between one xref insertion and the
next.

BTW, the original problem turns out to be related to section breaks
immediately preceding level-1 headings. At least in this case it is fixable
by search for ^b and replacing with ^& style = normal; but whether that's a
general solution I don't know.
 
W

Word Heretic

G'day "Jezebel" <[email protected]>,

Sometimes page breaks (as in chars, not para props) also cause similar
problems. If the number of paras is diff from before, rebuild... If I
wanted to be a REALLY tricky bicky, I'd dig up the heading offsets
from before, re-test em, and only restart from after the last found
one when I don't find one :)


Steve Hudson - Word Heretic
Want a hyperlinked index? S/W R&D? See WordHeretic.com

steve from wordheretic.com (Email replies require payment)


Jezebel reckoned:
 

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