Well, for starters it’s not Visual Basic but Javascript ;)
It stops on the first line because Javascript is case sensitive and “Function” should be “function”. Apart from that it should work nicely if you change the operation from changing the Row Height to setting the cell style. In the script below, the name of the applied cell style should be in “myCellStyle”.
When copying your code I found all single and double quotes were transformed into typographically correct “curly” ones. Javascript cannot work with these, they must be straight ones. It’s possible this forum changes them, so please make sure to check them after copying.
Adobe’s own ExtendScript Toolkit Editor, and other Javascript editors as well (I use TextPad) will apply syntax highlighting to keywords and properly formed text strings. You can use this to check; ‘function’, for example, should blue, just as “while” and “if” and other keywords. A text string without proper quotes appears ‘black’ (i.e., as regular text), but with the proper opening and closing quotes it appears in dark red.
Also, watch out for runaway comments. The very last line in your post contains one after the ‘//’, and this indicates the comment runs until the end of the line. However, there is a return missing and the ‘else’ part including the closing brackets should be on a new line.
function findTable(obj)
{
while (obj.constructor.name != "Table")
{
obj = obj.parent;
if (obj.constructor.name == "Application")
{
throw "Can’t find table";
}
}
return obj;
}
var myTable = 0;
if (app.documents.length > 0 && app.selection.length > 0)
{
myTable = findTable(app.selection[0]);
//Find styles cells formater
if (myTable.constructor.name == "Table")
{
app.findTextPreferences = app.changeTextPreferences = NothingEnum.nothing;
app.findTextPreferences.appliedParagraphStyle = "Heading 2";
var myCellStyle = myTable.findText();
app.findTextPreferences = app.changeTextPreferences = NothingEnum.nothing;
}
if (myCellStyle.length > 0)
{
for (var c = 0; c < myCellStyle.length; c++)
{
myCellStyle[c][/c].parent.appliedCellStyle = "myCellStyle";
}
} else
{
alert("Not found");
}
}