PDA

View Full Version : Numbered Lists and Cross-referencing



yac
04-13-2012, 07:44 AM
Hi Everyone,

I am new here. I was hoping to get help with what will hopefully be a small vba code. I have done some work with vba in excel but am very new to using it in word.

I am first trying to make cross referencing quicker and easier. I am trying to cross-reference numbered lists but I would want to only consider the numbered lists of a certain style.

In my example, I have operations numbers in the first column of a table and the second column is the explanation of the operation. I would like to be able to shortcut into inserting the operation. Currently I am using code like this...

Dim varOP As Variant
Dim varNumbered As Variant

varNumbered = ActiveDocument.GetCrossReferenceItems(wdRefTypeNumberedItem)


varOP = InputBox("Operation number", "Cross-referencing")
If IsNumeric(varOP) = True And varOP > 0 And varOP <= UBound(varNumbered) Then
Selection.TypeText Text:="OP "


Selection.InsertCrossReference ReferenceType:="Numbered item", _
ReferenceKind:=wdNumberRelativeContext, ReferenceItem:=varOP, _
InsertAsHyperlink:=True, IncludePosition:=False, SeparateNumbers:=False, _
SeparatorString:=" "
Else
MsgBox "Error with input!", , "Cross-referencing"
End If

This is bound to the keyboard shortcut Alt+C. My problem is if there is any other numbered lists in the document the order is not as expected. ie. typing in 6 for operation 060 would link to part 1 of operation 050.

Is there a way to fix this?

Thanks in advance,

yac



My follow up question will be, is there a way to generate a table where the first column is a cross-reference to the operation number and the second column is the title to the operation? I appreciate any help, thanks!