Here is the code:
If the first text frame in your document doesn't contain a table, then Anil's code doesn't work. It depends on where your table is and what state your document is in. Here are some approaches:
1. If you have an insertion point selected in a table, do this:
2. If you have a text frame selected which has a table in it, then do this:
3. To find all tables in the document and select the first one (though "first" is a variable and fluid concept here):
But do you really want to select a table? Whenever possible avoid working with selected items. To do something with a table, you could also address it as an object:
myTable = app.selection.tables;
myTable.cells.contents = "First cell";
Great! Simply superb.
Me trying to select all tables from a document. Then applying the table styles.
Once again thanks for the tips.
You can use this one-liner for that:
app.activeDocument.stories.everyItem().tables.everyItem().appliedTableStyle = myTableStyle;