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: Mon, 18 Oct 2004 22:21:24 -0700
Title: Re: Scripting MS Word "Insert Subdocument"
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.
However, in VBA, it looks pretty easy. There's an example in the VB Editor Help under "Subdocuments Collection" that looks like what you want to do. The AddFromFile Method inserts a subdocument from a file at the start of the selection, so first it inserts an empty line (paragraph) at the insertion point (selection). There's also another Method - AddFromRange - that converts an existing range of text in a master document into a new subdocument. The AddFromFile Method example:
ActiveDocument.Subdocuments.Expanded = True
Selection.EndKey Unit:=wdStory
Selection.InsertParagraphBefore
ActiveDocument.Subdocuments.AddFromFile Name:="Macintosh HD:Users:Shared:Setup.doc"
could be converted to a 'do Visual Basic' command in AppleScript in Word X or 2004. (Actually in 2004 you could do the first three lines in real AppleScript and only need 'do Visual Basic' for the final line, but you said you currently have Word X.) So that would be:
tell application "Microsoft Word"
do Visual Basic "ActiveDocument.Subdocuments.Expanded = True
Selection.EndKey Unit:=wdStory
Selection.InsertParagraphBefore
ActiveDocument.Subdocuments.AddFromFile Name:=\"Macintosh HD:Users:Shared:Setup.doc\""
end tell
In Word 2004, you could do
tell application "Microsoft Word"
set subdocuments expanded of active document to true
end key selection move unit a story
insert paragraph at (selection start of selection)
do Visual Basic "ActiveDocument.Subdocuments.AddFromFile Name:=\"Macintosh HD:Users:Shared:Setup.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