10 Replies Latest reply on Feb 23, 2016 7:40 AM by chrisnaylor

    Can anyone advise on the correct format for vbscript indexoptions ?

    chrisnaylor Level 1

      Can anyone advise on the correct format for vbscript indexoptions ?

       

      I am going around in circles trying to get it right.

       

      eg indexoptions.title when setting up a vbscript to generate an index

       

      I just can't find the right object to attach it to.

       

      There was both a Book and a Document open when these attempts were made:

       

      InDesign.ActiveBook.IndexOptions.Title = "Index New"  'Error 438 Object doesn't support this property or method

      'InDesign.Application.ActiveBook.IndexOptions.Title = "Index New" 'Error 438 Object doesn't support this property or method

      'Application.ActiveBook.IndexOptions.Title = "Index New" 'Error 424 Object Required Application

      'ActiveBook.IndexOptions.Title = "Index New" 'Error 424 Object Required ActiveBook

      'InDesign.Application.IndexOptions.Title = "Index New" 'Error 438 Object doesn't support this property or method

      'Application.IndexOptions.Title = "Index New"'Error 424 Object Required Application

      'MyInDesign.IndexGenerationOptions.IndexOptions.Title = "Index New" 'Error 438 Object doesn't support this property or method

      'MyIndexDocument.Indexes(1).IndexOptions.Title = "Index New" 'Error 438 Object doesn't support this property or method

      'MyIndexDocument.Indexes(1).Title = "Index New" 'Error 438 Object doesn't support this property or method

      'MyIndex.Title = "Index New" 'Error 438 Object doesn't support this property or method

      'myBook.Indexes(1).IndexOptions.Title = "Index New" 'Error 438 Object doesn't support this property or method

      'MyInDesign.ActiveBook.IndexOptions.Title = "Index New" 'Error 438 Object doesn't support this property or method

      'MyIndex.IndexOptions.Title = "Index New" 'Error 438 Object doesn't support this property or method

      'MyInDesign.IndexOptions.Title = "Index New" 'Error 438 Object doesn't support this property or method

      'IndexOptions.Title = "Index New" 'Error 424 Object Required IndexOptions

      'myDocument.IndexOptions.Title = "Index New" 'Error 438 Object doesn't support this property or method

      'IndexOptions.Title = "Index New" 'Error 424 Object Required IndexOptions

      'InDesign.IndexOptions.Title = "Index New" 'Error 438 Object doesn't support this property or method

      'myBook.IndexOptions.Title = "Index New" 'Error 438 Object doesn't support this property or method

       

      Any suggestions would be appreciated.

        • 1. Re: Can anyone advise on the correct format for vbscript indexoptions ?
          Peter Spier Most Valuable Participant (Moderator)

          Moved to the scripting forum in hopes someone here still does vbscript...

          • 2. Re: Can anyone advise on the correct format for vbscript indexoptions ?
            [Jongware] Most Valuable Participant

            Well, kudos for persistence - but you should really read up on the Document Object Model and pay attention to the hierarchy of objects. Randomly trying combinations will only lead to frustration.

             

            For instance, a Book object has nothing to do with indices. Yes, a Book has an Index property - but its description tells you it is Not The Index You Are Looking For. A Book has no IndexOptions, nor (plural) Indices.

            That takes care of at least half of your errors. Removing all of the "*.Index.IndexOptions" attempt takes care of yet another large chunk - "IndexOptions" are not part of an individual Index, they are part of either the Application (which is to set defaults so you may not want to change those) or Document.

             

            That said, I see at least one attempt that does make sense: Application.IndexOptions.Title. Even though this does not change the document but the default settings for new documents only, it still sounds like it should have worked. It is possible your link to InDesign does not work, but it is not totally unlikely that your syntax is just wrong.

             

            Adobe's Scripting Reference comes with a guide for Visual Basic, and the "general" reference also contains snippets and example lines for Visual Basic. I strongly suggest you to take a look at these, and try to run one or more ready-made examples, so you can check if the problem lies in the VBA-InDesign interface (if nothing runs), or if you just got stuck with using the correct VBA syntax.

            • 3. Re: Can anyone advise on the correct format for vbscript indexoptions ?
              chrisnaylor Level 1

              Many thanks for your reply.

               

              I appreciate your assistance.

               

              If I have this as the first lines of code:

               

              Set MyInDesign = CreateObject("InDesign.Application.CS5")

              InDesign.Application.IndexOptions.Title = "Index New"

               

              I get Error 438 Object doesn't support this property or method InDesign.Application

               

              I also tried:

               

              Set MyInDesign = CreateObject("InDesign.Application.CS5")
              myDir="D:\My Documents\"
              Set myDocument = myInDesign.Open(myDir & "Chap 1.indd")

              MyDocument.IndexOptions.Title = "Index New"

               

              and got the same error message instancing MyDocument.IndexOptions

               

              I agree that my efforts look pretty random - but I started off with the object model from the Excel VBA reference and just got increasingly desperate!

               

              Other code in the module works okay - if I remove any attempts at IndexOptions, which is a bit awkward as I'm really trying to get IndexOptions.IncludeBookDocuments working..

              • 4. Re: Can anyone advise on the correct format for vbscript indexoptions ?
                [Jongware] Most Valuable Participant

                I don't have a VBA + InDesign setup at home, I'd need to check this at work. Plewse remind me: are variable names in Visual Basic Case SensITive? In most other programming languages they are.

                • 5. Re: Can anyone advise on the correct format for vbscript indexoptions ?
                  chrisnaylor Level 1

                  Many thanks for your interest.

                   

                  Visual Basic isn't case-sensitive.

                   

                  I have put together a small piece of test code:

                   

                  Set MyInDesign = CreateObject("InDesign.Application.CS5")

                  myDir="D:\My Documents\"

                  Set myDocument = myInDesign.Open(myDir & "Chap 1.indd") 'any InDesign Document

                  InDesign.Application.IndexOptions.Title = "Index New"

                   

                  'InDesign.IndexOptions.Title = "Index New"  'alternate line of code

                  'MyDocument.IndexOptions.Title = "Index New"  'alternate line of code

                   

                  It opens the file ok but then fails with

                  Error 438 Object doesn't support this property or method

                   

                  I can't get any of the indexoptions to work.

                   

                  I'd be interested to hear your views.

                  • 6. Re: Can anyone advise on the correct format for vbscript indexoptions ?
                    Kasyan Servetsky Level 5

                    Try this:

                    MyDocument.IndexGenerationOptions.Title = "Index New"

                    • 7. Re: Can anyone advise on the correct format for vbscript indexoptions ?
                      Kasyan Servetsky Level 5

                      Hi Jongware,

                      I guess it's not chrisnaylor's mistake but a typo in VB reference:

                      22-02-2016 11-21-13.png

                      In the "Locals" we can see it should have been IndexGenerationOptions:

                      22-02-2016 11-23-35.png

                      Regards,
                      Kasyan

                      • 8. Re: Can anyone advise on the correct format for vbscript indexoptions ?
                        chrisnaylor Level 1

                        Excellent!

                         

                        That works!

                         

                        I could have spent the rest of my life trying to figure that one out!

                         

                        Who would have thought that the VB reference could be wrong!!

                        • 9. Re: Can anyone advise on the correct format for vbscript indexoptions ?
                          [Jongware] Most Valuable Participant

                          That is ... rather worrying!

                           

                          It has always been my understanding that the scripting interface is, well it is scripted – so from within a plugin (and no need to remind you that from InDesign's point of view, *everything* is a plugin) you can tag what gets exposed to the Scripting interface under what name, and then this automatically generates data for the JavaScript, AppleScript, and Visual Basic interfaces. If that indeed is the case, then there should not be any typo's!

                           

                          Just because I'm paranoid, I checked both my own JS reference for CS6 and Grefel's for CS 10.0 (InDesign ExtendScript API (10.0)) – and in both, this is called "IndexOptions". In my Word Object browser for CS4, I also see "IndexOptions" (but that's also the case in your screenshot so it does not tell us anything).

                           

                          Nice find, and glad you chimed in on this.

                          But seriously, worrying as well.

                          • 10. Re: Can anyone advise on the correct format for vbscript indexoptions ?
                            chrisnaylor Level 1

                            Just for the record, this is the working VB code - I appreciate the assistance I received:

                             

                            Rem  Generate Book Document indexes into separate Index document:

                            Set myBook = myInDesign.Open(myDir & "My Book.indb") 'Book must be open to index all Book Documents
                            Set myIndexDocument = myInDesign.Open(myDir & "Index.indd")
                            MyIndexDocument.Indexes.Add
                            Set MyIndex = MyIndexDocument.Indexes(1)

                            'Set up Index options:
                            MyIndexDocument.IndexGenerationOptions.Title = "Index"
                            MyIndexDocument.IndexGenerationOptions.TitleStyle="Chapter Head"                   'or whatever other style you have defined

                            MyIndexDocument.IndexGenerationOptions.Level1Style="First Paragraph"             'or whatever other style you have defined
                            MyIndexDocument.IndexGenerationOptions.Level2Style="Body Text"                      'or whatever other style you have defined
                            MyIndexDocument.IndexGenerationOptions.ReplaceExistingIndex = True
                            MyIndexDocument.IndexGenerationOptions.IncludeBookDocuments = True
                            Set MyPage = MyIndexDocument.Pages.Item(1)
                            myX = myPage.MarginPreferences.Left
                            myY = myPage.MarginPreferences.Top

                            'Generate the index:
                            myIndex.Generate MyPage , Array(myX, myY),,True 'autoflow text