Microsoft Word Create New Document
Microsoft Word Create New Document
- Subject: Microsoft Word Create New Document
- From: Gil Dawson <email@hidden>
- Date: Tue, 06 Dec 2016 15:02:39 -0800
Hi--
Anyone here familiar with scripting Microsoft Word?
I'm using Word 2008 for the Mac (version 12.3.6) on El Capitan (MacOS version 10.11.6).
My project is working pretty well, but I found a glitch that I don't understand. Perhaps someone here will have an idea to help me make sense of this.
This snippit works fine (and might also work OYM):
set TargetFile to (path to desktop) & "TestFileName"
tell application "Microsoft Word"
create new document set ReportDoc to the active document -- set ReportDoc to create new document
save as ReportDoc file name TargetFile insert text ("Some text" & return) at end of text object of active document set ReportText to text object of ReportDoc tell ReportText to insert text ("Some text" & return) at end save ReportDoc close ReportDoc end tell
But this one doesn't:
set TargetFile to (path to desktop) & "TestFileName"
tell application "Microsoft Word"
--create new document --set ReportDoc to the active document set ReportDoc to create new document
save as ReportDoc file name TargetFile insert text ("Some text" & return) at end of text object of active document set ReportText to text object of ReportDoc <--ERROR tell ReportText to insert text ("Some text" & return) at end save ReportDoc close ReportDoc end tell
The text of the error is
Microsoft Word got an error: The object you are trying to access does not exist.
The differences in the two scripts are solely in the three [un]commented lines in the middle.
The actual project takes several minutes to complete. While it's running, this glitch makes my computer vulnerable to my cat. If the "active document" should change, subsequent events will be directed to the new one.
I would prefer to direct events to a particular document, rather than any-which-one that's active at the moment.
Any ideas?
--Gil |
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden