7 Replies Latest reply on Mar 13, 2010 9:32 AM by AdobeScripts

    FindText problem




      Why doesn’t the code bellow find textToSearchFor in txt.Contens in CS4 with the method FindText?


      txt.Contens= "!B!bla bla bla!/B!. Bla bla bla bla. _"



          Private Function FindTextWrapper(ByVal txt As InDesign2CS.Text, ByVal textToSearchFor As String) As InDesign2CS.Objects

              Dim retObj As InDesign2CS.Objects


              If _MyIndesignApp.Version < "6" Then

                  retObj = txt.Search(textToSearchFor, False, False, )



                  _MyIndesignApp.FindTextPreferences = InDesign2CS.idNothingEnum.idNothing


                  ' Hämta alla startpunkter för bold

                  _MyIndesignApp.FindTextPreferences.FindWhat = textToSearchFor

                  retObj = txt.FindText()


                  _MyIndesignApp.FindTextPreferences = InDesign2CS.idNothingEnum.idNothing


              End If


              Return retObj

          End Function

      Any idea?



        • 1. Re: FindText problem
          Harbs. Level 6

          Maybe try:



          instead of:





          • 2. Re: FindText problem
            Makkanj Level 1

            Sorry, wrong spelling of me in the text. 


            In my program the txt.Contents is:


            txt.Contents= "!B!bla bla bla!/B!. Bla bla bla bla. _"

            • 3. Re: FindText problem
              Harbs. Level 6

              I'm not a VB man, but it does not look like full code. Can you give us a piece of working (or not working) code which illustrates the problem?



              • 4. Re: FindText problem
                Makkanj Level 1

                It's hard to give a good code example because there are a lot of code involved. But the code who calls the method looks like this:


                TextFrame.ParentStory.Texts.ItemByRange(TextFrame.ParentStory.Texts.Item(1).Characters.Ite m(1), TextFrame.ParentStory.Texts.Item(1).Characters.item(TextFrame.ParentStory.Texts.Item(1).C haracters.Count - 1)).Item(1).Contents = "!B! bla bla "

                StartObj = FindTextWrapper(TextFrame.ParentStory.Texts.Item(1), "!B!")


                StartObj.count = 0

                In some cases the findText method finds textToSearchFor in txt but in other cases not.

                • 5. Re: FindText problem
                  Makkanj Level 1

                  Hi again!


                  Just found out what was causing the problem.

                  If the layer is invisible than findtext will not find the text.

                  Is there a workaround for this, still having an invisible layer?


                  Best Regards

                  • 6. Re: FindText problem
                    Harbs. Level 6




                    • 7. Re: FindText problem
                      AdobeScripts Level 3

                      Makkanj wrote:


                      TextFrame.ParentStory.Texts.ItemByRange(TextFrame.ParentStory.Texts.Item(1).Characters.Ite m(1), TextFrame.ParentStory.Texts.Item(1).Characters.item(TextFrame.ParentStory.Texts .Item(1).Characters.Count - 1)).Item(1).Contents = "!B! bla bla "

                      You don't need to refer to ParentStory:

                      TextFrame.Texts.ItemByRange( _

                      TextFrame.Characters.Item(1), _

                      TextFrame.Characters.Item(-2) _

                      ).Item(1).Contents = "bla bla"


                      But first - even in your example - you need to check number of characters in TextFrame