GetCrossReferenceItems - myheadings - being truncated

O

Orla

I'm very new to this so would appreciate help from anyone who can.

I've written a routine which populates a table with all headings in
the MS Word document. It puts the description of the heading in one
column in a table, then puts a cross reference in the next column. My
ultimate aim is to limit the headings to specific sections, so i'm not
just reproducing a table of contents.

For now the problem I have is that the text (description of the
heading) is being truncated - so only the first 95 characters is being
written into the table - if the heading is any longer than this, the
remainder just gets lost.

Any ideas why 'myheadings(i)' in the code below is being truncated?
the offending line being:
.InsertAfter " " & myheadings(i))

Thanks in advance.
Orla
------------------------------------------------------------------------------

Sub headings()


arr_Xrefs = ActiveDocument.GetCrossReferenceItems(wdRefTypeHeading)
myheadings = ActiveDocument.GetCrossReferenceItems(wdRefTypeHeading)
Dim j As Integer

j = 1

For i = 1 To UBound(arr_Xrefs)


With Selection
Selection.Tables(1).Rows(j + 1).Select
Selection.Copy
Selection.Paste
Selection.Tables(1).Cell(j + 1, 2).Select
Selection.Font.Bold = False
.InsertAfter " " & myheadings(i)
.Collapse (wdCollapseEnd)
.InsertCrossReference _
ReferenceType:=wdRefTypeHeading, _
ReferenceKind:=wdNumberFullContext, _
ReferenceItem:=i, _
insertAsHyperlink:=True
Selection.Font.Bold = False
Selection.Collapse Direction:=wdCollapseEnd
ActiveDocument.UndoClear
j = j + 1
End With
Selection.Collapse (wdCollapseEnd)
ActiveDocument.UndoClear
Next i
End Sub
 

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