Re: GetCrossReferenceItems and sparse returns for wdCaptionTable

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Hi Russ

I think it's a bit more complicated than that and the documentation in VBA
help is, shall we say, incomplete.

The array that you get back from GetCrossReferenceItems is equivalent to the
"For which" box. The Reference Type you must give it is equivalent to the
"Reference Type" box in the dialog.

The "Reference Type" box includes caption labels. But none of the
wdReferenceType constants cope with caption labels. And obviously you can
create a cross-reference to, eg, a Table or Figure or Equation caption. So
you can use a string, eg:

Dim va As Variant
va = ActiveDocument.GetCrossReferenceItems("Table")

Or, you may have created your own label so you could use
Dim va As Variant
va = ActiveDocument.GetCrossReferenceItems("MyLabel")

Unlike "MyLabel", the Table, Figure and Equation labels are built-in. And
they have their own wdCaptionLabelID constants, wdCaptionTable,
wdCaptionFigure, wdCaptionEquation.

In an English install,
va = ActiveDocument.GetCrossReferenceItems("Table")
should produce the same results as
va = ActiveDocument.GetCrossReferenceItems(wdCaptionTable)

But since "Table" isn't "Table" except in English, it's safer to use the
constants.

But I have found in a large document with many tables, that
GetCrossReferenceItems does not always return an array containing an element
for all the tables in the document. It will do the first 100 or so tables,
but not the rest. It's not reproducible, and it seems to depend on document
complexity rather than sheer size. And, I don't think it's related to
hardware grunt, since giving it more processor speed and memory doesn't
solve the problem.

So I'm wondering if Greg found some mysterious way to solve that problem.

Shauna

Shauna Kelly. Microsoft MVP.
http://www.shaunakelly.com/word





"Russ" <drsN0SPAMmikle@xxxxxxxxxxxxxxxxxxxxx> wrote in message
news:C35A1C78.1EFA4%drsN0SPAMmikle@xxxxxxxxxxxxxxxxxxxxxxxx
Shauna et al.,

Here's what VBA help says about .GetCrossReferenceItems in my version of
Word. The asterisks were added by me for emphasis.

Although it says "for which box", it later only gives 5 types. Because
wdCaptionTable is not a wdRefCaptionTable type, maybe it is unreliable?
Maybe everything in the "for which box" has not been fully integrated or
debugged to work with that method yet?

===Quote
Returns an array of items that can be cross-referenced based on the
specified cross-reference type. The array corresponds to the items listed
in
the **For which box** in the Cross-reference dialog box (Insert menu).
Note An item returned by this method can be used as the ReferenceWhich
argument for the InsertCrossReference method.
Syntax
expression.GetCrossReferenceItems(ReferenceType)
expression Required. An expression that returns a Document object.
ReferenceType Required Variant. The type of item you want to insert a
cross-reference to. Can be one of the following WdReferenceType constants:
**wdRefTypeBookmark, wdRefTypeEndnote, wdRefTypeFootnote,
wdRefTypeHeading,
or wdRefTypeNumberedItem**.
====UnQuote

Hi Greg

I'm interested in following this up because I've had trouble over the
years
using .GetCrossReferenceItems. It doesn't always pick up all items, and I
had to roll my own routine, which runs much slower than the built-in one.

I can't see that
Set myRange = ActiveDocument.Range(Start:=0, End:=0)
is related to
oCaptions = _
ActiveDocument.GetCrossReferenceItems(wdCaptionTable)

But are you saying that setting a range variable to a more or less random
range immediately before running .GetCrossReferenceItems causes it to
work
reliably? Stranger things have happened in Word, so nothing would
surprise
me!

Shauna

Shauna Kelly. Microsoft MVP.
http://www.shaunakelly.com/word





<Greg Stanford> wrote in message news:200711814489no_spam_thanks@xxxxxx
Try this:

Set myRange = ActiveDocument.Range(Start:=0, End:=0)

oCaptions = _
ActiveDocument.GetCrossReferenceItems(wdCaptionTable)
...or wdCaptionFigure

I found that if a range was not set, then only about 9 elements would be
returned, and those 9 elements correspond to the first 9 elements in the
displayed cross reference window.

Good Luck

EggHeadCafe - .NET Developer Portal of Choice
http://www.eggheadcafe.com



--
Russ

drsmN0SPAMikleAThotmailD0Tcom.INVALID



.



Relevant Pages

  • Re: undefined vs. undefined (was: new Array() vs [])
    ... or to the array performance, I dared to move it to a new thread. ... And section 10.1.3 explains the assignment of the undefined value to ... to give a Reference type. ... var arr = ...
    (comp.lang.javascript)
  • Re: Array Fundamentals
    ... When a value-type object is created, C# allocates a single ... the values inside an Array should be allocated ... reside on the heap ... >type is that only the reference type exist on the heap. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: dbish (DBI::Shell 11.93 using DBI 1.51)
    ... some std SQL cmds work fine, ... DBI::Shell 11.93 using DBI 1.50 ... reference type: ARRAY ...
    (perl.dbi.users)
  • Re: foreach doesnt work with array of bools?
    ... In the code above I created an array of StringBuilder objects. ... Second loop calls the Append method ... it is a reference type and it too is read-only. ... Can I call the set methods? ...
    (microsoft.public.dotnet.languages.csharp)