Dropdown List of References

D

Debra Ann

I currently have a toolbar macro that a user can select to insert a
cross-reference to an endnote that is already referenced in the document.
What the macro does is have a pop-up box requesting the user to input the
reference number into a text box, it stores the reference in a variable, and
performs the cross-reference using the variable number.

Now the user's want to have the pop-up give them a list of the currently
available references. Is this possible to populate a drop-down list with the
current references in the document?
 
B

Bear

Debra Ann:

Yes. You must populate a list box with the current endnotes. This will be
similar to Word's built-in InsertCrossReference command. You can get the
collection of "referenceable" items using the GetCrossReferenceItems method
of the active document.

All you'd have to do is test the collection to pick out the endnotes.

I know this is terribly general. Let me know if you need more details.

Bear
 
D

Debra Ann

Yes I need more help. I've never pulled information into a list box or combo
box before so I'm not sure how to do it. What code would I write to pull up
all the endnotes in a combobox?

Thanks,
 
B

Bear

Debra Ann:

Let's assume you have a UserForm with a ListBox called lstEndnote, and a
command button called cmdInsert. You'll also need a variant field to get the
cross-references. Say we call this varXRefs.

Here's some code that would populate the ListBox with just the endnotes. It
also enables or disables the cmdInsert button based on whether or not the
active document has any endnotes. You'd have to write the code for the rest
of the UserForm controls, but I don't want to leave you without challenges.

Let me know if you get stuck.

Bear


Sub UpdateEndnoteList()

' Fill lstEndnote with the endnotes from the
' active document

Dim varXRefs As Variant
Dim Index As Integer

' Clear out any previous contents

Me.lstEndnote.Clear

' Load just the endnotes into varXRefs

varXRefs = ActiveDocument.GetCrossReferenceItems _
(ReferenceType:=wdRefTypeEndnote)

' Load the ListBox from varXRefs as an array

For Index = 1 To UBound(varXRefs)
Me.lstEndnote.AddItem varXRefs(Index)
Next Index

' Test whether the list has any entries and
' set command buttons accordingly

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

End Sub
 
D

Debra Ann

Bear:

I'm sorry it took so long to get back. I had a corrupted cache and
everytime I came out to the website to see if you had responded, I got a
"Service Temporarily Unavailable." I assumed the website was done but
finally figured out my cache was corrupted and kept showing the same screen
when I went out to the newsgroup.

Anyways ... the code worked great. I struggled by my self for quite a few
days and had one item in but needed to do the loop to get the rest of the
items listed. I can't thank you enough.

When I wrote to Microsoft about the problem I was having, I told them I was
lost without all of you. You all make my life so much easier; and, although
I always appreciated you all, I never appreciated you all as much as I did
when I didn't have access to the newsgroup.

Have a great day!
 

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