views:

179

answers:

1

Hi

I want to make a special list of figures with use of VBA and here I am using the function

myFigures = ActiveDocument.GetCrossReferenceItems(Referencetype:="Figure")

In my word document there are 20 figures, but myFigures only contains the first 10 figures (see my code below.).

I search the internet and found that others had the same problem, but I have not found any solutions.

My word is 2003 version

Please help me ....

Sub List()

Dim i As Long

Dim LowerValFig, UpperValFig As Integer

Dim myTables, myFigures as Variant

If ActiveDocument.Bookmarks.Count >= 1 Then

myFigures = ActiveDocument.GetCrossReferenceItems(Referencetype:="Figure")
' Test size...
LowerValFig = LBound(myFigures) 'Get the lower boundry number.
UpperValFig = UBound(myFigures) 'Get the upper boundry number
' Do something ....
For i = LBound(myFigures) To UBound(myFigures) ‘ should be 1…20, but is onlu 1…10
       'Do something ....
Next i

End If MsgBox ("Done ....")

End Sub*

A: 

Definitely something flaky with that. If I run the following code on a document that contains 32 Figure captions, the message boxes both display 32. However, if I uncomment the For Next loop, they only display 12 and the iteration ceases after the 12th item.

Dim i As Long

Dim myFigures As Variant

myFigures = ActiveDocument.GetCrossReferenceItems("Figure") MsgBox myFigures(UBound(myFigures)) MsgBox UBound(myFigures) 'For i = 1 To UBound(myFigures) ' MsgBox myFigures(i) 'Next i