1 Reply Latest reply on Dec 5, 2008 1:53 PM by (Olav_Kvern)

    ItemByRange problem

    Level 1
      Ole very kindly pointed me in the direction of the ItemByRange command, which I've used in this same script just fine.

      With the below statement, though, I'm getting an error that the object doesn't support this property or method (VB, Windows) but can't for the life of me figure out why!

      Set NumTxt = PTxt.Texts.ItemByRange(PTxt.Item(1).Paragraphs(i).Characters(in1%), PTxt.Item(1).Paragraphs(i).Characters(in2%))

      When I check the components of the statement things seem to be in order. For instance PTxt.Item(1).Contents displays the contents of PTxt and the following statement displays the character I expect
      MsgBox PTxt.Item(1).Paragraphs(i).Characters(in1%).Contents

      The ItemByRange statement, however, generate the error.

        • 1. Re: ItemByRange problem
          Level 1
          Hi Ken,

          Here's an example (the part you're interested in is in "mySnippet"):

          Rem ItemByRange.vbs
          Rem An InDesign CS4 VBScript
          Rem Shows how to use the ItemByRange method.
          Function main()
          Set myInDesign = CreateObject("InDesign.Application.CS4")
          mySetup myInDesign
          mySnippet myInDesign
          myTeardown myInDesign
          End Function
          Function mySetup(myInDesign)
          Set myDocument = myInDesign.Documents.Add
          Rem Create a text frame on page 1.
          Set myTextFrame = myDocument.Pages.Item(1).TextFrames.Add
          Rem Set the bounds of the text frame.
          myTextFrame.geometricBounds = myGetBounds(myDocument, myDocument.Pages.Item(1))
          Rem Fill the text frame with placeholder text.
          myTextFrame.Contents = idTextFrameContents.idPlaceholderText
          End Function
          Function mySnippet(myInDesign)
          Set myDocument = myInDesign.Documents.Item(1)
          Set myStory = myDocument.Stories.Item(1)
          Set myStart = myStory.Paragraphs.Item(1).Characters.Item(3)
          Set myEnd = myStory.Paragraphs.Item(2).Characters.Item(-3)
          Set myText = myStory.Texts.ItemByRange(myStart, myEnd)
          End Function
          Function myTeardown(myInDesign)
          End Function
          Function myGetBounds(myDocument, myPage)
          myPageWidth = myDocument.DocumentPreferences.PageWidth
          myPageHeight = myDocument.DocumentPreferences.PageHeight
          If myPage.Side = idPageSideOptions.idLeftHand Then
            myX2 = myPage.MarginPreferences.Left
            myX1 = myPage.MarginPreferences.Right
            myX1 = myPage.MarginPreferences.Left
            myX2 = myPage.MarginPreferences.Right
          End If
          myY1 = myPage.marginPreferences.Top
          myX2 = myPageWidth - myX2
          myY2 = myPageHeight - myPage.MarginPreferences.Bottom
          myGetBounds = Array(myY1, myX1, myY2, myX2)
          End Function