5 Replies Latest reply on May 11, 2010 9:04 PM by Robert P. Kyle

    Selecting a range of text in VB

    Robert P. Kyle

      I'm looking for the VB equivalent of this AppleScript:

       

      select text from character x to character y of parentStory (where parentStory is the parent story of the current insertion point)

       

      I get the idea from looking at snippets here and there that VB does this by using a loop, so I've gotten as far as

       

      myWindow.Select parentStory.Paragraphs.Item(1), true

       

      which works well enough, but when I add this line:

       

      myWindow.Select parentStory.Paragraphs.Item(2), true

       

      Paragraph 1 gets deselected. So obviously I'm missing something about the true/false parameter.

       

      I know this is a newbie sort of question, but I've done enough AppleScripting to get the point that it's not necessary to select something before acting upon it. In this case, I need to show it to the user.

        • 1. Re: Selecting a range of text in VB
          AdobeScripts Level 3

          hi Robert

           

          myWindows.Select parentStory.Texts.ItemByRange(parentStory.Paragraphs.Item(1),parentStory.Paragraphs.Item( 2)).Item(1)

           

          robin

          www.adobescripts.com

          • 2. Re: Selecting a range of text in VB
            Robert P. Kyle Level 1

            Robert, thanks for your response. Is ItemByRange something new in CS3 or 4 maybe? I neglected to mention that I'm working with InDesign 2.0 and the scripting guide for that version says nothing about ItemByRange. One of the many problems of the newspaper business these days is that we have to work with antique systems.

            • 3. Re: Selecting a range of text in VB
              Robert P. Kyle Level 1

              I have to correct myself. I see now that itembyrange IS part of the VB dictionary in ID2.0, it's just listed under Objects not Texts, where I was looking.

               

              But when I run your code, I get a runtime error: Object doesn't support this property or method. So I've probably fouled something up in the way I'm defining myWindow or parentStory. I will continue banging my head on this wall until something softens.

              • 4. Re: Selecting a range of text in VB
                AdobeScripts Level 3

                Hi Robert,

                I have to correct myself. I see now that itembyrange IS part of the VB dictionary in ID2.0, it's just listed under Objects not Texts, where I was looking.

                 

                But when I run your code, I get a runtime error: Object doesn't support this property or method. So I've probably fouled something up in the way I'm defining myWindow or parentStory. I will continue banging my head on this wall until something softens.

                Try to delete last .Item(1):

                 

                myWindow.Select parentStory.Texts.ItemByRange( _

                parentStory.Paragraphs.Item(1), _

                parentStory.Paragr aphs.Item(2))

                 

                Later I'll try to check right syntax for ID 2.0.x.

                 

                robin

                 

                www.adobescripts.co.uk

                • 5. Re: Selecting a range of text in VB
                  Robert P. Kyle Level 1

                  I found part of the answer in an old post: "InDesign 2.x does not have the ItemByRange method on any text objects other than Characters, so you have to do something like the following:

                   

                  Set Par1 = mystory.Paragraphs.Item(1).Characters.Item(1)
                  Set Par2 = mystory.Paragraphs.Item(5).Characters.Item(-1)
                  myDocument.Select mystory.Characters.ItemByRange(Par1, Par2).Item(1)

                   

                  But, to my dismay, it does not work when I transplant it into a script for InCopy 2.0. I realize that the rest of the world has pretty much moved on to some version of CS, but if anyone has even a dim memory of how to select itembyrange in InCopy, please tell me.