VBA script for automatically indexing topics

A big disadvantage with InDesign's indexing system is that you cannot automatically index all occurences of topics currently in the index.
Instead, you have to find an occurence of each topic in the document itself and go to the Index menus and then click New Page Reference...Add All, for each index topic individually.
To get around this, I have been trying to produce a VBA script to automatically index all occurrences in a document of the topics currently in the document index.
I have been using the MS Excel VBA development environment but find the definitions of the object model in the Excel VBA browser rather inadequate and ambiguous .
Is there a more thorough reference work for these?
The plan was to start by taking each individual topic in the index which I tried to access with something along the lines of:
MyDocument.Index.Topic(1)
This hasn't worked.
The plan then was to take each index topic and use it to find an occurence in the document of that topic and then use that occurence to invoke the New Page Reference...Add All option to index all occcurences of that selected term, using something like:
MyDocument.PageReferences.Add
Again, without success.
Any guidance or suggestions would be appreciated.

Dear Peter,
Many thanks for your posting, that was very helpful.
This is the state of the script so far (I have added a large number of MsgBox entries - these aren't needed, they are just for debugging purposes during development):
'VBA script which tries to work through all of the topics in the index and automatically index each occurence of them in the current text frame:
main
Function main()
Set MyInDesign = CreateObject("InDesign.Application.CS4")
If MyInDesign.Documents.Count > 0 Then
    Set MyDocument = MyInDesign.ActiveDocument
    Set MyPage = MyDocument.Pages.Item(1)
    Set MyTextFrame = MyPage.TextFrames.Item(1)
    Set MyStory = MyTextFrame.ParentStory
    Set MyIndex = MyDocument.Indexes(1)
    Set MyTopics = MyIndex.AllTopics
    MyIndexesCount = MyDocument.Indexes.Count
    MsgBox "Current indexes Count: " & MyIndexesCount
    MyIndexTopicsCount = MyTopics.Count
    MsgBox "Current index topics Count: " & MyIndexTopicsCount
    For i = 1 To MyTopics.Count Step 1 'work through the topics
MyIndexTerm=MyTopics(i)
MsgBox "Current indexes Topic: " & MyIndexTerm
'search for MyIndexTerm :
        'Clear Find preferences:
        MyInDesign.FindTextPreferences = idNothingEnum.idNothing
        'Set up search paramaters:
        If MyIndexTerm <> "" Then
            MyInDesign.FindTextPreferences.FindWhat = MyIndexTerm
            'Set search options:
            MyInDesign.FindChangeTextOptions.CaseSensitive = False
            MyInDesign.FindChangeTextOptions.IncludeFootnotes = False
            MyInDesign.FindChangeTextOptions.IncludeHiddenLayers = False
            MyInDesign.FindChangeTextOptions.IncludeLockedLayersForFind = False
            MyInDesign.FindChangeTextOptions.IncludeLockedStoriesForFind = False
            MyInDesign.FindChangeTextOptions.IncludeMasterPages = False
            MyInDesign.FindChangeTextOptions.WholeWord = False
            'Search for the string:
            Set MyFoundItems = MyDocument.FindText 'this ought to be limited to the Story, not the Document eg MyStory
         MsgBox "Found index terms:" & MyFoundItems.Count
            For j = MyFoundItems.Count To 1 Step -1
               MyTopics(i).PageReferences.Add MyFoundItems(j)
            Next
           'Clear preference:
            MyInDesign.FindTextPreferences = idNothingEnum.idNothing
            'Having found it, add page reference:
         'MyDocument.PageReferences.Add
        Else
            MsgBox "No search term specified"
        End If
Response=MsgBox ("Continue?", vbYesNo)
If Response = vbNo then
  Exit For
End If
   Next
'Set up Index options:
MyIndex.IndexOptions.Title = "Index"
MyIndex.IndexOptions(1).TitleStyle="Chapter Head"
MyIndex.IndexOptions(1).ReplaceExistingIndex = True
'Generate the index:
MyIndex.Generate
Else
    MsgBox ("Please open a document, select an object, and try again.")
End If
End Function
There are a couple of problem areas still:
1. Index terms appear to be added irrespective of whether or not that particular page reference already exists in the index.
This can result in duplicate page references under each topic - especially if the script is run several times.
Is there any way of avoiding these duplicate references?
2. I haven't yet suceeded in getting the script to generate the index - so far I've had to do it manually after the script has run.
The problem lies somewhere in the code to set up the index options and then generate the index.
3. It might be useful to be able to limit the indexing to the curent story rather than the whole document - but I haven't yet got it to do that.
Best wishes.

Similar Messages

  • IND 3 or 4: script for making INDEX

    Hi,
    When typesetting books in Indesign cs3/4 (OSX), some of our texts contain words tagged like this: [r]word[#r].
    Those are the words which should end up in the index. It's a timeconsuming job to select these tagged words by hand, apply the 'create a new index entry' (apple-u), and move on to the next one.
    Can someone write a script that automates this nasty job for me? Search for the word between the paranthesis, apply apple-u, move on to the next one.
    I hope it won't be difficult for someone who is used scripting around in indesign.....
    greetings, frits

    Hi Frits,
    Check out this script (post5):
    Peter Kahrel, "Footnote behaviour" #5, 3 Dec 2008 7:24 am
    Kasyan

  • Programmin​g VBA script for AWR

    Hello everyone, i'd like to make some VBA scripts to run automatically models for AWR.
    CAn anyone tell me how to do this ? or where i can find it ? 
    THank you very much.

    Hello,
        The AWR API is very powerful and can do many things.   It is hard to tell what you are trying to accomplish with this request. Please provide more details.  Additionally, you can find many example scrips here:  https://awrcorp.com/download/faq/english/scripts/s​cripts.aspx
    We also have another page that has resources for scripting here:   https://oldwiki.awrcorp.com/public/scripting/doku.​php
    AWR Support

  • VBA script for custom Outlook 2010 calendar "first day of week"

    I need Outlook 2010 to use "week starting with the Saturday before Jan 1" as "first week of year" to match our company payroll calendar. (For example, Saturday 12/26/2015-Sunday 1/3/2016 would be "first week of 2016".) Is there
    a way to do this in a VBA script?
    -Thanks, zogg

    Hello zogg,
    The settings are stored in the registry at
    HKCU\Software\Microsoft\Office\15.0\Outlook\Options\Calendar
    where 15.0 stands for Outlook
    2013.
    Make changes in
    the Outlook settings and see which registry values change and in what way depending
    on the settings you change. 
    Also take a look at the How
    can I get the work week and day number in VBA (outlook 2010)? page which states the following:
    WW = Format(Now, "ww") & "." & Weekday(Now, vbMonday)
    The "Format" function returns an expression from a string formatted with the provided "format" argument (ww in
    this case, which returns the week of the year) and the Weekday() function
    returns the numbered day of the week where the first day is a VBDayOfWeek enumeration
    provided as the second argument (vbMonday in
    this case).

  • Shell script for Automatic Awr Report

    Hi Good Morning,
    I have a requirement to generate the AWR report daily between (10AM - 06PM , 10AM - 01PM , 01PM - 10PM) . I have the below script for this . But the issue is this script is working only when i run it two times and before running i have to delete snap_list.lst file. Please let me know what is the problem in this script and how to resolve it.
    Script :
    dt=`date +%d%m%Y`
    cd /orabkp/awr_report
    chmod 777 *
    rm -rf snap_list.lst
    touch snap_list.lst
    #rm -rf snap_list.lst
    #rm -rf snap_list.lst
    sqlplus -s " /as sysdba " <<EOF > snap_list.lst
    host sleep 10
    @/oracle/scripts/cron_scripts/rpt1.sql;
    @?/rdbms/admin/awrrpt.sql
    HTML
    1
    `cat snap_list.lst | grep "10:0" | awk '{print $1}'`
    `cat snap_list.lst | grep "13:0" | awk '{print $1}'`
    awrrpt\_$dt\_10AM\-01PM.html
    prompt 2
    @?/rdbms/admin/awrrpt.sql
    HTML
    1
    `cat snap_list.lst | grep "13:0" | awk '{print $1}'`
    `cat snap_list.lst | grep "18:0" | awk '{print $1}'`
    awrrpt\_$dt\_01PM\-06PM.html
    @?/rdbms/admin/awrrpt.sql
    HTML
    1
    `cat snap_list.lst | grep "10:0" | awk '{print $1}'`
    `cat snap_list.lst | grep "18:0" | awk '{print $1}'`
    awrrpt\_$dt\_10AM\-06PM.html
    @?/rdbms/admin/addmrpt.sql
    `cat snap_list.lst | grep "06:0" | awk '{print $1}'`
    `cat snap_list.lst | grep "12:0" | awk '{print $1}'`
    ADDM_REPORT\_$dt\_10AM\-06PM.txt
    EOF
    exit
    cat /oracle/scripts/cron_scripts/rpt1.sql
    host echo 1
    host sleep 10
    @?/rdbms/admin/awrrpt.sql
    HTML
    1
    `cat snap_list.lst | grep "10:0" | awk '{print $1}'`
    `cat snap_list.lst | grep "13:0" | awk '{print $1}'`
    awrrpt\_$dt\_10AM\-01PM.html
    Regards
    Rajasekar

    Hi,
    Modify & Try this script used for rac awr ..
    #!/bin/ksh
    set -x
    ORACLE_SID=DBSID
    ORACLE_HOME=/u01/app/ora11g/product/11.2.0/db_1
    export ORACLE_HOME
    TERM=vt100
    export TERM
    PATH=/usr/bin:/etc:/usr/sbin:/usr/ucb:/usr/local/bin:/usr/bin/X11:/bin:/sbin:.
    PATH=$ORACLE_HOME/bin:$PATH
    export DT=`date '+%d_%b_%Y_%HH_%MM'`
    export ORACLE_BASE ORACLE_SID ORACLE_HOME PATH DT
    echo $DT
    MAIL="[email protected]"
    CMAIL="[email protected]"
    AWRR="/u01/DBA_Scripts/AWR_REPO"
    sqlplus -s "/ as sysdba"<<EOFSQL
    set head off
    set feed off
    spool /tmp/bsnap.lst
    select max(SNAP_ID)- 3 from dba_hist_snapshot;
    spool off
    spool /tmp/esnap.lst
    select max(SNAP_ID) from dba_hist_snapshot;
    spool off
    spool /tmp/iname.lst
    select instance_name from v\$instance;
    spool off
    spool /tmp/dname.lst
    select database_name from v\$database;
    spool off
    spool /tmp/inum.lst
    select instance_number from v\$instance;
    spool off
    spool /tmp/dbid.lst
    select dbid from v\$database;
    spool off
    EOFSQL
    BSNAP=`cat /tmp/bsnap.lst | tail -1 | awk '{ print $1}'`;export BSNAP
    ESNAP=`cat /tmp/esnap.lst | tail -1 | awk '{ print $1}'`;export ESNAP
    INAME=`cat /tmp/iname.lst | tail -1 | awk '{ print $1}'`;export INAME
    DNAME=`cat /tmp/dname.lst | tail -1 | awk '{ print $1}'`;export DNAME
    INUM=`cat /tmp/inum.lst | tail -1 | awk '{ print $1}'`;export INUM
    DID=`cat /tmp/dbid.lst| tail -1 | awk '{ print $1}'`;export DID
    echo "Begin Snap  : $BSNAP"
    echo "End Snap    : $ESNAP"
    #echo "InstanceName: $INAME"
    echo "DB Name     : $DNAME"
    #echo "InstanceId  : $INUM"
    echo "DB ID       : $DID"
    sqlplus -s "/ as sysdba"<<EOFSQL
          define  inst_num     = $INUM;
          define  num_days     = 12;
          define  inst_name    = 'ALL';
          define  db_name      = '$DNAME';
          define  dbid         = $DID;
          define  begin_snap   = $BSNAP;
          define  end_snap     = $ESNAP;
          define  report_type  = 'html';
          define  report_name  = $AWRR/Awr_report_$DT.html
          @@?/rdbms/admin/awrgrpti
    EOFSQL
    cat /u01/DBA_Scripts/mail_body.txt | mailx -a $AWRR/Awr_report_$DT.html -c $CMAIL -s "DB Report - DB "  $MAILThanks,
    Ajay More
    http://www.moreajays.com

  • Possible to make a script for duplicating index entries?

    I would like to make things easier than they seem to be.
    I have several references (1:st level topics) already that are correct with page numbers and all that.
    Now, I would like to create a 1:st level topic, under which I put "duplicates" of these already indexed references and put them as 2:nd level topics, under the main, 1:st level, topic.
    Example.
    Let's say I have these references (1:st level topics) already, with correct page numbers and everything:
    Audi 4-6, 8
    BMW 7, 21-24
    Citroen 11, 12
    Mercedes 80
    Volkswagen 31-36
    Okay, these are perfectly indexed and all the pages are correct.
    Now, I would like to have these references as both 1:st level topics, and also as second level topic references under the main topic "Cars", like this:
    Cars 4-80
    Audi 4-6, 8
    BMW 7, 21-24
    Citroen 11, 12
    Mercedes 80
    Volkswagen 31-36
    My question is. Is it possible to achieve this by a script, so I can copy (duplicate) all these references and put them under the topic "Cars" too (preserving the 1:st level topics too of course), without having to go to each of the pages and create new topics all over again for every single finished topic, that I intend to put under the main topic "Cars"?
    Just to inform you, the above named 5 topics, are NOT only the topics I want to put under "Cars"... there are like a hundred :).
    Is it possible to make a script like this? Or do I have to do all the work ALL OVER again?
    Martin

    Hmmm… This one copies all files which have 'flash' (could by x-shockwave-flash) string in mime type to /tmp/flash. Hope it will be helpful.
    for i in ~/.opera/cache4/* ; do file -i -F '' $i | grep flash | cut -d ' ' -f 1 | xargs cp -t /tmp/flash 2>/dev/null ; done
    UPDATE:
    Sorry, there was a little bug, I've just changed 'video' to 'flash' ('video' coundn't match 'x-shockwave-flash').
    Last edited by zergu (2008-12-25 21:16:38)

  • Script for automatic delete of archive logs/redologs

    Hi Experts,
    Do you have any idea on how to create a shell script. Actually the function of it, is to automatically deletes the archive logs/redologs if reaches the limit. Or is there any parameter to change to set the automatic deletion of archive logs/redologs.
    Regards

    Hi,
    at first, archivelogs should always be saved to tape before you delete them. If you don't want to backup them, may be for a test system, you can suppress them in ORACLE instead to delete them later.
    You can run the database in "NOARCHIVE LOG MODE". If you do so, the online redologs are not archived, they are still reused and overwritten. You can not run an online Backup, when the database is in noarchive log mode. If you want to backup the database, you have to run an offline backup.
    Do not use the NOARCHIVE LOG MODE for production or developemet systems.
    To change the archive log mode:
    shutdown the database
    startup mount;
    alter database noarchivelog;
    alter database open;
    archive log list       will show the actual status
    regards Ulrich

  • Script for automate export of idml for many docs (perhaps using hot folder)

    Hi all,
    I am looking for a solution to automate export many INDD docs to IDML. Did anyone have done such a solution?
    Thanks in advance!

    HI,
    You will be certainly interested in Peter Kahrel's Batch Exporter Script.
    Not related to HotFolder though for what I know of.
    Free script Batch convert/export InDesign documents | Peter Kahrel
    Best,
    Loic
    http://www.ozalto.com

  • Shell Script for automatic backup

    Hello Every one,
    We have windows network and sun solaris sparc box. (both from Sun Box and from Windows machine I can communcate using Telnet.)
    I wish to take data backup of a system having windows operating system, into
    the sun solaris sparc box automatically by week end .
    Can anyone help me with the shell script which does this operation.
    Regards,
    Dwarak

    first of all, is there nfs running? and on windoze box, do u have any nfs client program running?
    you cant transfer files frm the windoze machine via telnet..
    once you can settle the above, what you can do is a simple copy script and put it in your crontab.

  • Script for automatically copying DVDs/CDs to disk on insert?

    I just started to copy about 500 Data-DVDs (and some CDs) to an external FAT32 USB-disk. I do that by dragging the mounted disk from the desktop to the drive while holding down the option-key.
    Is there a way to automate that? Would be easier if the Mac started the copying whenever a new DVD/CD is mounted on the desktop. And ejecting the disk by itself would be nice too. That way I'd be sure to notice that another copy is done and could put in the next disk ...

    Udo Schmitz wrote:
    Hi,
    I want to copy DVDs/CDs to a harddisk as well. But to an external USB drive.
    So, when "/dev/disk1" is my MacBooks internal optical drive, how do I address the external USB-HD?
    Apple-Script doesn't want me to use the path: "/Volumes/FILME/" ...
    You'll want to leave the superdrive path the same but change the duplicate to desktop part to your own external hd. I'm pretty sure you get it just making sure.
    Applescript doesn't mind the path you chose just the UNIX style slash format oppose to mac colon delimintated. Try this
    (/Volumes/FILME/...) as POSIX path
    --or
    :Volumes:FILME:...

  • Script for automatically shutting flapping interface

    dear all,
    I am looking for a eem scrip  so that when interface flap up/down for atleast five times, script should shutdown this interface and no shut another interface  based on logs generated. and after three hours or so it should again no shut the flaping link.
    Thanks
    Saju

    Hello,
    I wrote a similar script to passive-interface EIGRP if it is flapping.  The logic remains the same.  Just change the trigger and what actions you want it to take.
    event manager applet CIRCUIT_STABILITY authorization bypass
    event syslog occurs 3 pattern " %DUAL-5-NBRCHANGE: EIGRP-IPv4 10: Neighbor 10.51.2.1 .*down" period 45000 maxrun 120
    action 1.0 cli command "enable"
    action 1.1 syslog priority errors msg "%EEM-ACTION-ENGAGED% due to Multiple EIGRP Flaps"
    action 2.0 cli command "conf t"
    action 3.0 cli command "router eigrp 10"
    action 4.0 cli command "passive-interface tunnel 512"
    action 4.1 syslog priority errors msg "Tunnel 512 has been made passive by TEST"

  • Indexing Topic Titles (anyway to automate this?)

    Hello,
    Is there any way to automatically index topic titles as
    titles, without RH breaking them down into individual
    keywords?

    Hi there TWKC
    Not really. You *COULD* accomplish it by editing the "Phrase
    List" file to include all the Topic Titles. But that would be as
    much work as simply indexing them individually.
    On second thought, have you tried just displaying the Topic
    List, selecting all the topics, clicking and dragging into the pane
    area where the Index keywords are listed? I'm thinking that should
    do it.
    How is JWS these days anyway? (I once worked there - Back in
    2000/2001)
    Cheers... Rick

  • Rc script, for activate numlock on ttys

    Hello, and sorry for my bad English...
    I've made a script, for automatically turn on numlock on ttys (Script is little edited version of gentoo script)
    You just add 'numlock' to DAEMONS in rc.conf
    can You test it works for everybody? And submit me any suggestions?
    PKGBUILD in AUR, name 'numlock'
    EDIT -- Sorry for bad forum, mod please move topic to: [PKGBUILDs & ABS Support]
    Last edited by canni (2007-09-08 19:17:46)

    I usually use screen(1) to capture info/debug msg from the tunnel. For example:
    screen -d -m -S ntc-tunnel ssh -YNMS /tmp/ssh-%r@%h:%p -D $socks_port -L $ntcgrid_bind_port:ntcgrid:22 ntc

  • Apple Script for deleting podcasts

    I subscribe to a lot of podcasts, but I don't want to keep them in my iTunes library after I'm done listening to them. Is there an Apple Script for automatically deleting podcasts? Thanks.

    Thanks - once I'm in Automator and select Music, I don't see any options for finding Podcasts. Any suggestions which item/step I should select next in Automator? Thanks.

  • HELP!! Using a vba script in Outlook to copy attachments to c:\temp folders automatically

    Hi
    I'm brand new to Visual Basic really - you will be able to tell that I am a complete beginner. I wouldn't be posting here but I had tried asking other Forums but have not got any responses.
    This is the problem:- I've found a basic VB script to copy attachments within Outlook 2000 Inbox to the c:temp folder when a new email arrives in. When I debug the script in Outlook > Tools > Macros , it just seems to loop round and round within the
    top function called Application_Startup () and never attempts the objInbox_ItemAdd() function which is the important part. Please can anyone say what is wrong.
    I'm putting all this code within Project1 > Microsoft Outlook Objects > This OutlookSession - I bet I'm putting all this code in the wrong place aren't I? Please help anyone.
    Dim WithEvents objInbox As Outlook.Items
    Private Sub Application_Startup()
    Set objInbox = Session.GetDefaultFolder(olFolderInbox).Items
    End Sub
    Private Sub objInbox_ItemAdd(ByVal Item As Object)
    If Item.Class = olMail Then
    If Item.Attachments.Count > 0 Then
    Dim objAttachments As Outlook.Attachments
    Set objAttachments = Item.Attachments
    For Each objAttach In objAttachments
    ' Does not handle duplicate filename scenarios
    objAttach.SaveAsFile "C:\temp" & objAttach.FileName
    Next
    Set objAttachments = Nothing
    End If
    End If
    End Sub
    Also, I've set the Security to Low within Outlook > Tools> Macros > Security and a bit baffled why this won't run.
    Just for info, I got this VBScript solution from:-
    Outlook Visual Basic for Applications Rules
    Kind Regards
    Matt
    p.s I'm stuck with Outlook 2000 due to a limitation with some Legacy software that my company is still using.

    Thanks jrv.
    At the moment - I don't have the time to learn VBA better along with learning the other things I have an intested in already (e.g. PowerScript) - My customer has an outstanding fault which need fixing urgently. I've spent about 5 hours so fa trying to get
    a VBA script to work withing Outlook but to no avail. I might ask around my company to see if any one else can help or post this on a non-Microsoft forum I think.
    Cheers all the same
    Matt
    So you sold a job to do something you do not knowhow to do.  You are getting paid.  It is your job to learn or to hire someone with the skills you have sold.  We cannot produce custom scripts for an obsolete version of Outlook 2000.. 
    O2000 is almost 15 years old. It is not secure as no security patches have been released for it for almost 10 years.  It is old technology which none of us care to remember unless you want to pay us for the assistance.
    Here is the link to the instructions in th KB that you completely ignored:
    http://support.microsoft.com/kb/235852/EN-US
    It shows you exactly how to do this in Outlook 2000.  You must read all of the instructions carefully.  YOu must try all example code and be sure you understand how it works.  Post all issues with how to use VBA in the Outlook VBA developers
    forum AFTER you have tried that code and have a specific question and not just a requirement for someone to fix this for you.
    The code in the article is explicit to Outlook 2000.  The code you are using is only usable in Outlook 2002 and later.,  You must follow the examples for Outlook 2000 as outlined in your original article.
    If you want to be a technician you need to learn all of these things.  Just knowing how to install a PC is not sufficient if you are going to be a contractor.
    VBA is VBA.  Posting here will not change that.  This is an Admin scarping forum and not an office VBA forum.  VBA is NOT VBScript.  No matter how much it looks like VBScript it is not.
    You cannot just copy VBScript into a VBA module and expect it to work. 
    You have sold the job of a programmer and Outlook developer with no skills in that area.  Is that fair to your customer?
    There are hundreds of skilled developers who have spent good money and time learning to do these things. You cannot just past some things you found on the Internet into a file and ask someone to fix it for you. 
    Start by learning the difference between script and VB.  Next you need to learn what an event is and how it is generated.  The code you posted does nothing in Outlook because it is not Outlook code.
    No.  I am not picking on you.  I am trying to get you to wake up and spend time learning your profession.  It is a lot of fun and actually pretty easy but only if you do your homework.
    ¯\_(ツ)_/¯

Maybe you are looking for

  • Data Federator data lineage and impact analysis

    Hi, I am looking for the use of data lineage and impact analysis feature in data federator at Universe level. Can I know which objects are using which fields by uisng impact feature in the data federator. Thanks in Advance.

  • ITunes Store Error 8003

    I was downloading extras for a movie of mine and got error 8003. My network is fine, iTunes has full access to the Internet; if it didn't the movie wouldn't download would it? Really trying to avoid messing with my system configuration (Windows 7). I

  • Problems using JNI and JSP in WebLogic 6.0

    Hello everybody. My problem is that I've got a Java class that is called from a JSP. That class connects to a C function and it returns a String. A want this string to be shown by the JSP. The code is: JSP <html> <head> <title>prueba JNI</title> </he

  • How to use 'right click' command of windows in mac firefox

    how do i use the windows 'right click commands in mac firefox == This happened == Every time Firefox opened == begining

  • Transportable Module IN OWB

    I am trying to configure an OWB 'transportable module' to perform an expdb/impdb, as defined in the Mark Rittman weblog page http://www.rittmanmead.com/2006/04/10/using-data-pump-and-transportable-tablespaces-with-owb10gr2-paris/ I am going for use o