Re: Scripting MS Word "Insert Subdocument"
Re: Scripting MS Word "Insert Subdocument"
- Subject: Re: Scripting MS Word "Insert Subdocument"
- From: Paul Berkowitz <email@hidden>
- Date: Tue, 19 Oct 2004 12:18:27 -0700
Title: Re: Scripting MS Word "Insert Subdocument"
On 10/18/04 10:21 PM, "Paul Berkowitz" <email@hidden> wrote:
On 10/18/04 1:46 PM, "Barbara Bolduc" <email@hidden> wrote:
At this point, there are no subdocuments—the command I am looking is to create the subdocuments using the insert subdocuments command, so I don't have to go through the same repetitive steps over and over again. I typically have around 100 existing documents to be inserted into a master document for multiple projects. So anyway, here's the question again since I guess I didn't explain it well the first time.
Does anyone know if you can use Applescript to insert existing documents into a master document, thereby creating subdocuments, in MS Word X (or later—I can upgrade). The manual command is "insert subdocument" on the Master Toolbar, and "import subdocument" on the menu. They seem to do the same thing.
I spent some time looking and you're right - there doesn't appear to be any way to do this with the 2004 AppleScript. I've filed a bug report.
OK. I got a reply from someone at MacBU. It turns out that in Word 2004, you can do the whole thing without recourse to 'do Visual Basic'. Amazingly enough, the way to make a new subdocument in AppleScript is by using the 'make new' command - which is the proper AS way to do it. Unfortunately, there is nothing in the Reference or dictionary that explains how to do it here, so I've now bugged that instead. I have been assured that they are planning on adding examples that show how to make an instance of every class, including subdocument.
It turns out that the equivalent to VB's AddFromRange method is to make the subdocument at a text range (text object); and the equivalent to VB's AddFromFile as I used in the 'do Visual Basic' example yesterday - the equivalent to Insert Subdocument in the UI that you asked about is to 'make new subdocument with properties {path:"Mac HD:path:to:file"} Even though 'path' is listed as an r/o read-only property of subdocument, it is settable at inception, like many r/o properties. The dictionary and Reference should say so too. And the subdocument gets made at the selection in Outline View, as in the UI. The dictionary and Reference should say that to.
For Word X, stick with do Visual Basic, of course. For 2004, here's a sample script provided by someone at MacBU that shows the entire process of making a document, turning it into a master document, re-aligning (demoting) headings as needed, and making subdocuments both from text and from a file. The bit inserting a subdocument is just the last two lines of the script - that may be all you need.
----------------------------------------
tell application "Microsoft Word"
activate
close every document saving no
-- create a master document
set newDoc to make new document
set newName to name of newDoc
set masterDoc to document newName
-- create a subdocument
set newDoc to make new document
set newName to name of newDoc
set subDoc to document newName
-- set view type to Master View
set view type of view of active window of masterDoc to master view
-- create master document content
set content of text object of masterDoc to ¬
"Master document" & return & ¬
"Subdocument 1" & return & ¬
"Subdocument 2" & return
set para2 to paragraph 2 of masterDoc
set para3 to paragraph 3 of masterDoc
outline demote para2
outline demote para3
-- create subdocument content
set content of text object of subDoc to "Subdocument 3" & return
-- get Documents folder
set docFolder to (path to documents folder) as Unicode text
-- ########## CREATE SUBDOCUMENTS FROM RANGES ##########
set subdoc1 to make new subdocument at text object of para3
set subdoc2 to make new subdocument at text object of para2
-- save master document
save as masterDoc file name docFolder & "Master.doc"
-- name changed - reset reference variables
set masterDoc to document "Master.doc"
set subdoc1 to subdocument 1 of masterDoc
set subdoc2 to subdocument 2 of masterDoc
-- save subdocument file
save as subDoc file name docFolder & "subDoc.doc"
-- name changed - reset reference variable
set subDoc to document "subDoc.doc"
-- ########## CREATE SUBDOCUMENT FROM FILE ##########
-- Note: The new subdocument replaces the selection
select last character of masterDoc
set subdoc3 to make new subdocument in masterDoc with properties ¬
{path:docFolder & "subDoc.doc"}
end tell
----------------------------------------
--
Paul Berkowitz
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden