Skip to main content
Inspiring
September 6, 2015
Answered

How to change text only in cell

  • September 6, 2015
  • 2 replies
  • 472 views

Hi experts,

How to find-change text only in the cell?

How to make this script working?

         var
         mFCarray = [
                            ["2030", "2031"], 
                            ["2029", "2030"], 
                            ["2028", "2029"], 
                            ["2027", "2028"], 
                            ["2026", "2027"], 
                            ["2025", "2026"], 
                            ["2024", "2025"], 
                            ["2023", "2024"], 
                            ["2022", "2023"], 
                            ["2021", "2022"], 
                            ["2020", "2021"], 
                            ["2019", "2020"], 
                            ["2018", "2019"], 
                            ["2017", "2018"], 
                            ["2016", "2017"], 
                            ["2015", "2016"], 
                            ["2014", "2015"], 
                            ["2013", "2014"], 
                            ["2012", "2013"]
                            ],
                        myDocuments = app.documents.everyItem().stories.everyItem().tables.everyItem().cells.everyItem().texts.everyItem(),
                        cFCprefs;

                       app.findGrepPreferences = changeGrepPreferences = null; 
                       
                        while (cFCprefs = mFCarray.shift() ) {
                            app.findGrepPreferences.findWhat = cFCprefs[0];
                            app.changeGrepPreferences.changeTo = cFCprefs[1];
                            myDocuments.changeGrep();
                            }
                       
                        app.findGrepPreferences = changeGrepPreferences = null; 

Regard

John
                       

This topic has been closed for replies.
Correct answer kobugi pawel

Hi,

in case that some cell is empty, script will cause error with myDocuments, as not every cell has a text.

you should try to shortcut myDocuments to:

myDocuments = app.documents.everyItem().stories.everyItem().tables.everyItem().cells.everyItem(),

or even better:

myDocuments = app.documents.everyItem().stories.everyItem().tables.everyItem().

regards

Pawel

2 replies

JohnwhiteAuthor
Inspiring
September 6, 2015

Thank you Pawel, thank you so much.

Regard

John

Peter Kahrel
Community Expert
Community Expert
September 6, 2015

That script works fine over here. In what way does it not work at your end? An error? Does nothing happen?

JohnwhiteAuthor
Inspiring
September 6, 2015

Hi pkahrel,

The script in my side error with this line:

myDocuments.changeGrep();

Regard

John

kobugi pawelCorrect answer
Participating Frequently
September 6, 2015

Hi,

in case that some cell is empty, script will cause error with myDocuments, as not every cell has a text.

you should try to shortcut myDocuments to:

myDocuments = app.documents.everyItem().stories.everyItem().tables.everyItem().cells.everyItem(),

or even better:

myDocuments = app.documents.everyItem().stories.everyItem().tables.everyItem().

regards

Pawel