The way to make a new blank document equivalent to
Application.Workbooks.Add
is
make new workbook
Normally in AppleScript, you expect to be able to specify many, or most, of the properties of a workbook in a with properties parameter, right at creation time. (A scripter would expect that only elements, if any are needed, would have to be added afterwards.) That isn't possible with Microsoft Word documents, but it is possible with Microsoft Excel.
All of the properties listed in the dictionary as read/write, with the exception of those that require that a workbook first be set up as a shared workbook, can be set
with
properties {...}
in the make new command. In Visual Basic for Applications (VBA), you would have to set these after making the new workbook and setting a reference to it in a variable.
You can do that in AppleScript, too, as you will see below, but you can also set any of the following properties at inception. Here they are all set to something other than the default values, and they all work, including setting a password.
tell application "Microsoft Excel"
set newWkbk to make new workbook with properties ¬
{acceptlabels in formulas:false, ¬
conflict resolution:¬
local session changes, date 1904:¬
false, display drawing objects:¬
placeholders, personal view list settings:¬
false, personal view print settings:¬
false, precision as displayed:true,
save link values:false, ¬
update remote references:¬
false, template remove external data:¬
true, keep change history:¬
true, remove personal information:¬
true, password:"yyyyy", write password:¬
"zzzzz", read only recommended:¬
true, workbook comments:"Hi, there"}
end tellYou can verify that these are non-default settings by first running
properties of active workbook
on a regular blank new workbook, copying the result to a text editor, and then running it again after making another workbook using the script above with non-default property values. Compare the results. If you save and then reopen the workbook, you will be asked for passwords, and all of the other properties are all set already, including the ones recorded in the Calculation dialog box. You can see these in Excel by doing more or less the following, depending on your version:
On the Excel menu, click Preferences, and then under Formulas and Lists, click Calculation.
Setting properties at inception in the make new command is a useful timesaver, and something to consider when you start writing your own AppleScripts in the future. When converting your VBA macros, it is probably simpler to mimic the standard VBA macro line by line.
Dim newWkbk As Workbook Set newWkbk = Workbooks.Add With newWkbk .AcceptLabelsInFormulas = False .PrecisionAsDisplayed = True ' etc. End With
In AppleScript:
tell application "Microsoft Excel" set newWkbk to make new workbook tell newWkbk set accept labels in formulas to false set precision as displayed to true -- etc end tell end tell
You omit the
Dim
statement, because there isn't one in AppleScript.


