List of cross-references based on custom style

J

Jennifer H

Hi,

I have been trying to find a way to make it easy for our authors to
cross-reference to Appendix headings. We use custom styles called App Heading
1 to 5. These appear in the Cross-reference dialog box under the Reference
Type: Numbered Items. But so too do all the other numbered items.

I would like to be able to do any of the following:
1. Filter the 'For Which' list in the Cross-Reference dialog box to show
only the numbered items I want; or
2. Use a custom form to show a filtered list.

I have been successful with programatically changing the settings in the
Cross-reference dialog box using the SendKeys method to. But don't know how
to filter the Numbered Items list further.
I have created forms before, and suspect that I might need to use an array
and maybe the GetCrossReferenceItems method, but not sure how to filter the
list to specific items.

Your help would be appreciated.
Cheers,
Jennifer H
 
B

Bear

Jennifer:

Is it essential that you use outline numbering for your Appendix styles?
Could you use a SEQ field to number your Appendices? You could then declare
that SEQ field to be a caption, and x-ref by Appendix captions. The term
"Appendix" or whatever you name the SEQ field would appear as a Reference
Type in the Cross-Reference dialog box.

Failing that, you're either going to rebuild the entire Cross-Reference
dialog box (not necessarily a bad thing as you can make it behave better) OR
you're going to have one command for most x-refs, and a custom command and
dialog box for Appendix x-refs.

Bear
 
J

Jennifer H

Hi Bear,

I'm thinking along the lines of a separate dialog box for Appendix x-ref.
Would prefer to stick with outline numbering. It's fairly stable at this
stage and my authors are used to it.

Cheers,
Jennifer
 
B

Bear

Jennifer:

Perhaps this might be of some help to you.

I use a modeless userform for my Insert Cross-Reference dialog box. I don't
use the "magic" forms approach, although I've never experienced any problems
that I could attribute to magic forms with certainty.

So my InsertCrossReference() sub deletes then creates a new instance of the
userform class each time it's invoked. Here's how.

~~~~~
Sub InsertCrossReference()

' Traps Word InsertCrossReference command and opens the
' Insert Cross Reference dialog box. Special coding is used
' for this nonmodal dialog form.

' Delete any instances and create a new instance

If Not objInsertCrossReference Is Nothing Then
Set objInsertCrossReference = Nothing
End If

Set objInsertCrossReference = New frmInsertCrossReference

objInsertCrossReference.Show

End Sub
~~~~~

The form persists between invocations, so it must be destroyed at the end of
the Word session. I do this in an AutoExit sub.

~~~~~
Public Sub AutoExit()

'MsgBox "AutoExit event from Custom Tools"

' Destroy modeless forms

....
[I destroy several modeless forms here, including the X-ref one.]
....

If Not objInsertCrossReference Is Nothing Then
Set objInsertCrossReference = Nothing
End If

' Destroy session-durable forms

If Not objInsertTable Is Nothing Then
Set objInsertTable = Nothing
End If

End Sub
~~~~~

All the other code -- though this may not be the best practice -- is in the
userform. That's where already-created code would help you most, but that's
the area where I can't help you much, because the application is so
different. You already know what type of x-ref you're looking for, etc. But
do let me know how you sort out the appendix numbered items from the other
items in GetCrossReferenceItems, won't you?

And think about your custom dialog box some more. Why not include chapters
and topics? Your dialog could let the user choose between short lists of
chapters, appendices, or topic titles. That way the dialog makes more "sense"
as a custom tool -- it makes the most frequently used x-refs available.

You could phase it in -- putting the requisite conrols in place but leaving
them all disabled except the Appendix ones. Then you enable them as you add
the code.

Enough daydreaming. Back to work.

Bear
 
J

Jennifer H

Thanks Bear,

Intercepting the built-in Cross-Reference dialog box and replacing it with a
custom version is a great idea. Didn't know that was possible. Thanks for the
code.

The idea about including chapters and topics got me thinking too. It would
be good to include all headings and the appendix headings as one grouping.
That would make more sense. I can see other applications there too.

Ahh, so now we come to the filtering out of appendix numbered items from the
others. That's the bit where I get stuck. Still no clues on that one, but
will keep plugging at it. Hopefully someone with throw in a clue somewhere.

Will definately post the solution, if/when it comes.

Cheers,
Jennifer

Bear said:
Jennifer:

Perhaps this might be of some help to you.

I use a modeless userform for my Insert Cross-Reference dialog box. I don't
use the "magic" forms approach, although I've never experienced any problems
that I could attribute to magic forms with certainty.

So my InsertCrossReference() sub deletes then creates a new instance of the
userform class each time it's invoked. Here's how.

~~~~~
Sub InsertCrossReference()

' Traps Word InsertCrossReference command and opens the
' Insert Cross Reference dialog box. Special coding is used
' for this nonmodal dialog form.

' Delete any instances and create a new instance

If Not objInsertCrossReference Is Nothing Then
Set objInsertCrossReference = Nothing
End If

Set objInsertCrossReference = New frmInsertCrossReference

objInsertCrossReference.Show

End Sub
~~~~~

The form persists between invocations, so it must be destroyed at the end of
the Word session. I do this in an AutoExit sub.

~~~~~
Public Sub AutoExit()

'MsgBox "AutoExit event from Custom Tools"

' Destroy modeless forms

...
[I destroy several modeless forms here, including the X-ref one.]
...

If Not objInsertCrossReference Is Nothing Then
Set objInsertCrossReference = Nothing
End If

' Destroy session-durable forms

If Not objInsertTable Is Nothing Then
Set objInsertTable = Nothing
End If

End Sub
~~~~~

All the other code -- though this may not be the best practice -- is in the
userform. That's where already-created code would help you most, but that's
the area where I can't help you much, because the application is so
different. You already know what type of x-ref you're looking for, etc. But
do let me know how you sort out the appendix numbered items from the other
items in GetCrossReferenceItems, won't you?

And think about your custom dialog box some more. Why not include chapters
and topics? Your dialog could let the user choose between short lists of
chapters, appendices, or topic titles. That way the dialog makes more "sense"
as a custom tool -- it makes the most frequently used x-refs available.

You could phase it in -- putting the requisite conrols in place but leaving
them all disabled except the Appendix ones. Then you enable them as you add
the code.

Enough daydreaming. Back to work.

Bear
 
B

Bear

Jennifer:

I think an appropriate strategy would be a group of radio buttons to select
the type:

Figure
Table
Chapter
Appendix
Headings

so the user could zero in on the type of object he's cross-referencing, or
select Headings and see all the Chapter, Appendix, and topic headings.

Each click event would repopulate a list of objects of that type.

You'd also want a customized Format list box to present the formats you
actually use, and maybe checkboxes for Hyperlink (which we default to
cleared, i.e. no hyperlinks) and Use "On Page" to reproduce the most helpful
built-in options. We also have a Company Format check box which disables all
the formatting options and just inserts the cross-reference in our "approved"
format for each type.

Here's my generic sub that fills the item list when the type option button
changes. The variant variables are global to the userform, so they're defined
in General Declarations at the beginning of the form code.

Dim varXRefs As Variant
Dim varRefType As Variant

Sub UpdateItemList()

' Use varRefType to fill the Item list accordingly

Me.lstItem.Clear

varXRefs = ActiveDocument.GetCrossReferenceItems _
(ReferenceType:=varRefType)
For Index = 1 To UBound(varXRefs)
Me.lstItem.AddItem varXRefs(Index)
Next Index

If Me.lstItem.ListCount > 0 Then
Me.lstItem.ListIndex = 0
Me.cmdInsert.Enabled = True
Else
Me.cmdInsert.Enabled = False
End If

End Sub

So the GetCrossReferenceItems is being loaded into the variant varXRefs,
which becomes an array. I only get the cross-reference items of the type the
user wants, as indicated by the previously set varRefType. Then I run through
the array and add each item in it to my userform list.

Check the object browser for WdReferenceType to see what you can ask for. An
obscure factoid is that for captions (figures, tables, equations, etc.) you
can set varRefType to the caption name.

Bear
 
J

Jennifer H

Bear, you've been reading my mind ;-)

I've already produced the user form with the radio buttons and was starting
to tackle the matter of repopulating the list based on the selected radio
button. Your solution came at exactly the right time.

As to the FormatList box and other options, I intend to hardcode these to
comply with company standards. But will set a variable for the reference kind
(varRefKind) when a radio button is selected, to cover the difference between
captions (figures & tables) and numbered items (headings and auto numbers).

Thanks,
Jennifer
 
M

Mike Starr

I know just enough to be really interested in what you're doing here but not
enough to be of any assistance. I haven't had the opportunity to study VBA
enough to understand it at a detail level. However, I'd certainly love to
see the final outcome of your work... the existing xref dialog box is the
bane of my existence (well, that and kitties stomping across my keyboard but
that's a whole different story, isn't it?).

One thing to add to Bear's list would be bookmarks (present in the existing
dialog box).

Mike
 
B

Bear

Mike:

Actually, my dialog box does include bookmarks, but I didn't want to dump
too much detail on Jennifer in one slug. I have six types, the sixth being
"Other." Selecting other enables a list box, in which I've listed all the
other types found in the document, one of which may well be bookmarks.

I just updated my profile with a decipherable e-mail address, and if you can
contact me offlist, I'd be happy to try to send you a copy of my x-ref
replacement. I can't promise it quickly, as I'd have to strip out proprietary
stuff to make it "sterile." Also bear in mind that it's only tested on Word
2000.

Bear
 

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