Applescript Save in active document error/problem

0 down vote favorite

Hello Community,




I have a problem indicating my AppleScript an error while running.


Error: "Microsoft Word" hast found an error: "active document" can´t read." number -1728 from active document

Word Version: Word 2016 Home & Business for Mac


Code:


tell application "Microsoft Word"
active
open "OSX_El_Capitan:Documents:Header:MyHeader.dotx"
set theDoc to active document
tell theDoc
insert file at text object of bookmark "test" file name "OSX_El_Capitan:Documents:Template:DocTemp"
save in "OSX_El_Capitan:Documents:My Save Name.docx"
end tell
end tell


The scripts has stopped in line "save in..." and marked this line.

The other parts over "save in" are working.

Whether it maybe is a problem active document I do not know.


Thanks

OS X El Capitan (10.11.5)

Posted on Sep 9, 2016 6:37 AM

Reply
5 replies

Sep 12, 2016 1:07 AM in response to Pierre L.

Hello Pierre L, thanks for your answer.


If the document already exists, the script back to me no errors.

In this case, the text will be written to the file but not saved. And I think that he opens a separate file.

If the document does not exists, the script back to me one error.

error "file \":OSX_El_Capitan:Documents:My Save Name\" can not be converted to type alias." number -1700 from file ":OSX_El_Capitan:Documents:My Save Name.docx" to alias


Current code:

tell application "Microsoft Word"
active
open "OSX_El_Capitan:Documents:Header:MyHeader.dotx"
set theDoc to active document
tell theDoc
insert file at text object of bookmark "test" file name "OSX_El_Capitan:Documents:Template:DocTemp"

set theFile to POSIX file "/Documents/My Save Name.docx" as alias

save in theFile

end tell

end tell

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Applescript Save in active document error/problem

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.