How do I create 25 tables in Microsoft Word, one table per page. I’ve figured out how to do it in Pages with the below code, but the Microsoft Word vocabulary is more complex.
repeat with i from 1 to 25
tell page i
make table with properties {column count:2, row count: 9}
tell table 1
set position to {25, 25 + (792 * (i - 1))}
set width of first column to 100
set width of second column to 465
end tell
end tell
end repeat
This script inserts a table on the first page, then puts a page break before it and repeats as many times as you set maxPages to.
Note that the script assumes you are starting with a completely blank document.
use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions
set maxPages to 25
set tblRows to 3
set tblColumns to 4
tell application "Microsoft Word"
set doc to active document
repeat with i from 1 to maxPages
set tbl to make new table at doc with properties {text object:(create range doc start 0 end 0), number of rows:tblRows, number of columns:tblColumns}
set rng to collapse range (text object of tbl) direction collapse start
if i < maxPages then
insert break at rng break type page break
end if
end repeat
end tell
Many thanks. I will test this out.
I ran your script, it does indeed create 25 pages and 25 tables, but the tables are invisible.
I played around the the border properties and table gridlines properties to no avail.
Anybody know how to make the gridlines visible?
To make the gridlines visible:
tell application "Microsoft Word"
set table gridlines of view of active window to true
end tell
To set a 1-point border on every cell of a table:
tell application "Microsoft Word"
set tbl to table 1 of active document
tell border options of tbl
set inside line style to line style single
set inside line width to line width100 point
set outside line style to line style single
set outside line width to line width100 point
end tell
end tell