How to enhance Word 2010 Indexing Features with VBA

Microsoft Word 2010, Windows 7

I need to do two things pertaining to an ordinary Word index (the kind you find in the back of books):  For one,  when I "Include the selected text in the index of the document" I would like it to show up as red text in the "Show paragraph marks and other hidden formatting symbols" view.  Secondly, I would like to view my current index without inserting it into a document.  For example, I'm marking an entery and the Mark Index Entry dialog box is open.  I'm marking the entry as a "Subentry" but I'm not sure what I used in the "Main Entry" for other text of similar concordance.  I can open the index in my document but it would be much easier to open it in another window so I can take a quick glance at it without having to close the Mark Index Entry dialog.  Any suggestions on how to accomplish these two index procedures using VBA?

Les Coover

Microsoft Community Team,

 

Concerning: “Show paragraph marks and other hidden formatting symbols”(hereafter SHF) view—Index Marks in red.  Right now I can do this: • In SHF view highlight index mark, then set font color to red.

 

When I “insert an index into document” (found on References tab) everything has black text.  The reason I want the Index Marks in red is so these marks can be easily found when in SHF view and hidden in normal view (SHF bivariate  toggle).  What I would like is VBA code that will paint something like {·XE·”Index·Main·Concordance:subentry”·} in red every time I use the New Index Entry dialog.

 

In regard to “previewing an index:” the following code prints a list of all bookmarks in the Immediate window of the VBA editor:

 

Sub ListBookmarks()

Dim bk As Bookmark

Dim bkList As String

  For Each bk In ActiveDocument.Bookmarks

  bkList = bkList & bk.Name & vbCr

  Next

Debug.Print bkList

End Sub

 

With “Show bookmarks” checked in the Options → Advanced → Show document content section, bookmarks are displayed with light gray brackets.  When SHF is on, index marks are shown, for example, as {·XE·”Index·Main·Concordance:subentry”·}.  It seems there should be a way to “collect” all the index marks and display them in the Immediate window.

 

Ordered the book “Word 2007 Macros & VBA Made Easy” by Hart-Davis.  Perhaps, after a review of VBA, I will come up with a solution. 

 

Suggestions always welcomed!

 

Les

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

re. the thing about keeping the index open in a separate window, ou may be able to use the split document view to do that, although I cannot see how right now.

Alternatively, you could create a completely separate document that contains

 a. an RD field that references your document

 b. a copy of the INDEX field that you have in your document.

Then, you could keep your main document and your "RD" document open, mark up entries in the main document, and update the INDEX field in the "RD" document either after each entry is marke, or each time you wanted to check your index.

So if for example your main document is c:\a\maindocument1.docx" and had an INDEX field like

{ INDEX \c "2" }

your RD document would contain

{ RD "c:\\a\\maindocument1.docx" } 

{ INDEX \c "2" }

(Where all the {} pairs are the special field code braces that you can insert using ctrl-F9 on Windows Word).

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

Thanks Peter,

I'm keeping your suggestion and will get into it more when I get the book “Word 2007 Macros & VBA Made Easy” by Hart-Davis.  Thank you so much for this worthwhile information.

Les

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

Thanks to Peter Jamieson and Doug Robbins MS MVPs

Here's what I did:

(1) Move the index to the very top of the document.  It can be moved to the end after the References section is added when the document is finalized.

(2) Use View → New Window to place a copy of original document on second monitor.

(3) Word makes temporary file extension for each document: docx1 and docx2

(4) When a new Index Entry (XE) Field is added, the following Macro is run:

Sub WMME_Index_Entry_XE_Fields()
    ' Format all Index Entry Field Codes dark red       
    ' If you place an Index Entry (XE) Field in a footnote, this
    ' macro won’t change font color--you have to do it with styles
    ' When referring to information in a footnote, the easiest way
    ' is to place the XE field in the body (text) with added words "in footnote"
    
    Dim fld As Field
    For Each fld In ActiveDocument.Fields
    If fld.Type = wdFieldIndexEntry Then fld.Select
    Selection.Font.ColorIndex = wdDarkRed
    Next
    
     ' Update_index
     Selection.HomeKey Unit:=wdStory
    ' Ctrl-Home
    Selection.Fields.Update
    ' F9
    Application.GoBack
    Application.GoBack
    Application.GoBack
    Application.GoBack
    Application.GoBack
    Application.GoBack
    ' Ctrl -Alt - Z (6 times) returns focus to the position in
    ' document where you are working
End Sub

References:

Dorey, Susan. Indexing and Microsoft Word. Aug. 17, 2010. http://www.susandoreydesigns.com/software/IndexingAndWord.pdf (accessed Oct. 24, 2014).

Hart-Davis, Guy. Word 2007 Macros & VBA Made Easy. New York: McGraw Hill, 2009.

 

 

 

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

Although that macro does the job, it's inefficient to select things (which moves the cursor and forces Word to redraw the screen) and then have to move the cursor back to its original position. A better plan is to use the properties of the fields themselves to determine where the changes are made. Also, VBA knows where the index is, separately from its membership in the Fields collection, so you don't have to put the index at the beginning of the document unless you need to do it for some other reason.

The following macro does the same work as yours with less fuss:

Sub Highlight_XE_Fields()
    Dim fld As Field
    
    For Each fld In ActiveDocument.Fields
        If fld.Type = wdFieldIndexEntry Then
            fld.Code.Font.ColorIndex = wdDarkRed
        End If
    Next
    
    ActiveDocument.Indexes(1).Update
End Sub

_____________________________
https://jay-freedman.info

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

Rather than using the RD field, I was going to suggest using copy the index then use Paste Special, with link, to another blank document.  That way you could look at the index while creating new entries and you could update the index as required between adding entries as required.

As well, I suggest you take a look at this free online download book by a professional editor.  He has a large collection of macros in it. You may be able to adapt one or more of them to do things you need.

Word - Macros for Writers, Editors and Proofreaders

by Paul Beverley, LCGI

http://www.archivepub.co.uk/book.html

.
*****
.
As computer scientists we are trained to communicate with the dumbest things in the world – computers –
so you’d think we’d be able to communicate quite well with people.
Prof. Doug Fisher

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

Thanks Jay,

Yes, your code is a definite improvement!

Coover

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

 
 

Question Info


Last updated October 5, 2021 Views 417 Applies to: