Welcome to the Excel Forum

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed.

Please Register to Remove these Ads

Please Register to Remove these Ads



Reply
  #1  
Old 06-23-2009, 11:28 AM
hutch@edge.net hutch@edge.net is offline
Valued Forum Contributor
 
Join Date: 23 Mar 2008
Location: Tennessee
MS Office Version:Office 2007
Posts: 462
hutch@edge.net is becoming part of the community
Macro to add index entries

Please Register to Remove these Ads

Greetings, Gurus. I am trying to help automate the task of adding index entries in MS Word 2007. Unfortunately, I know NOTHING about Word macros.

In the below macro, I have selected the word "warehouse", then recorded the steps to adding "warehouse" to the index. Ideally I would like to select another word, run the macro, and THAT word would be added to the index. Unfortunately, that isn't happening.

Here's what I've got. Can someone help me to add the SELECTED word to the index?

Thanks in advance.

Code:
Sub Add_to_Index()
    ActiveWindow.ActivePane.View.ShowAll = True
    ActiveDocument.Indexes.MarkAllEntries Range:=Selection.Range, Entry:= _
        "warehouse", EntryAutoText:="warehouse", CrossReference:="", _
        CrossReferenceAutoText:="", BookmarkName:="", Bold:=False, Italic:=False
    ActiveWindow.ActivePane.View.ShowAll = Not ActiveWindow.ActivePane.View. _
        ShowAll
End Sub

Last edited by hutch@edge.net; 06-23-2009 at 12:02 PM.
Reply With Quote
  #2  
Old 06-23-2009, 11:38 AM
Andy Pope's Avatar
Andy Pope Andy Pope is offline
Forum Guru
 
Join Date: 10 May 2004
Location: Essex, UK
MS Office Version:2003 & 2007 sp2
Posts: 7,223
Andy Pope Has a higher level of understanding Andy Pope Has a higher level of understanding Andy Pope Has a higher level of understanding Andy Pope Has a higher level of understanding Andy Pope Has a higher level of understanding Andy Pope Has a higher level of understanding Andy Pope Has a higher level of understanding Andy Pope Has a higher level of understanding
Re: Macro to add index entries

Like this maybe.

Code:
Sub Add_to_Index()
    ActiveDocument.Indexes.MarkAllEntries Range:=Selection.Range, _
                    Entry:=Selection.Range.Text, _
                    EntryAutoText:=Selection.Range.Text, _
                    CrossReference:="", CrossReferenceAutoText:="", BookmarkName:="", _
                    Bold:=False, Italic:=False
End Sub
__________________
Cheers
Andy
www.andypope.info
Reply With Quote
  #3  
Old 06-23-2009, 12:02 PM
hutch@edge.net hutch@edge.net is offline
Valued Forum Contributor
 
Join Date: 23 Mar 2008
Location: Tennessee
MS Office Version:Office 2007
Posts: 462
hutch@edge.net is becoming part of the community
Re: Macro to add index entries

Perfect, Andy. Thanks.

Have a good one!
Reply With Quote


Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Forum Jump