4 Replies Latest reply on Jul 17, 2008 11:34 PM by (Marc_Boehler)

    ChangeTextPreferences only for last or specified page

      Hi folks,

      my VB Script generates a new Page each time it is started, and adds a textframe to the last page. Into this textframe i write 2 variables from a database (by using Woodwing SmartCatalog Plugin). First is the Headline followed by a linebreak and a second line of text.

      Now I use:

      myInDesign.FindTextPreferences.FindWhat = "second line of text"
      myInDesign.ChangeTextPreferences.pointSize = 8
      myInDesign.ChangeTextPreferences.FillColor = myColor

      to find and change the pointsize and fillcolor of the "second line of text". Works excelent so far. To get to the point:

      Is it possible limit the search and change only the last page of the document? Or maybe even better to the specific textbox on the last page of the document? I am very new to VB and Indesign scripting, so maybe it`s no big thing. I am really stuck with this so if someone could help me I whould be very glad.

        • 1. Re: ChangeTextPreferences only for last or specified page
          Level 1
          Hi Marc,

          You control the scope of the find/change operation by the object that you tell to perform the search. In this case, all you need to do is set up your find/change (as you've already done), then get a reference to the text frame, then:

          Rem Given a reference to a text frame "myTextFrame"...


          • 2. Re: ChangeTextPreferences only for last or specified page
            Level 1
            Hi Ole,

            thanks for your fast reply. To be honest I dont really know how to do that. I think my problem is to fully understand the document structure. Here is my complete script. It works in CS3. What exactly do I have to change to search, find and change only the myProductHeadlineText on the last page?

            Set myInDesign = CreateObject("InDesign.Application.CS3")
            Set myDocument = myInDesign.ActiveDocument
            Set myPage = myDocument.Pages.LastItem

            Rem Add a new page to the document
            Set myActiveDocument = myInDesign.ActiveDocument.Pages.Add
            Set myProductHeadlineText = myPage.TextFrames.Add
            myProductHeadlineText.GeometricBounds = Array(35, 75, 52, 135)
            myProductHeadlineText.Contents = "Headline"
            myProductHeadlineText.ParentStory.Texts.Item(1).AppliedFont = "Myriad Pro"
            myProductHeadlineText.ParentStory.Texts.Item(1).FontStyle = "Bold"
            myProductHeadlineText.ParentStory.Texts.Item(1).PointSize = 11
            myProductHeadlineText.InsertionPoints.Item(-1).Contents = vbCr & "Second Headline"

            Rem Set the find options
            myInDesign.FindTextPreferences = idNothingEnum.idNothing
            myInDesign.ChangeTextPreferences = idNothingEnum.idNothing

            Rem Search for "Second Headline" String ang change pointsize
            myInDesign.FindTextPreferences.FindWhat = "Second Headline"
            myInDesign.ChangeTextPreferences.pointSize = 8
            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

            Rem Count changed textfields
            Set myFoundItems = myInDesign.Documents.Item(1).ChangeText
            MsgBox ("Changed " & CStr(myFoundItems.Count) & " instances of the search string.")
            myInDesign.FindTextPreferences = idNothingEnum.idNothing
            myInDesign.ChangeTextPreferences = idNothingEnum.idNothing
            • 3. Re: ChangeTextPreferences only for last or specified page
              Level 1
              Hi Marc,

              Instead of:

              Set myFoundItems = myInDesign.Documents.Item(1).ChangeText

              ...which tells the *document* to change the text, try:

              Set myFoundItems = myProductHeadlineText.Texts.Item(1).ChangeText

              ...or, to be safe:

              Set myFoundItems = myProductHeadlineText.ParentStory.ChangeText

              It's all about which object you tell to "ChangeText".


              • 4. Re: ChangeTextPreferences only for last or specified page
                Level 1
                Big Thanks Ole!
                Now I understood this.
                Works perfect! THX!