Join the Stack Overflow Community
Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

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.

share|improve this question
    
Try save as file name "OSX_El_Capitan:Documents:My Save Name.docx" – vadian Sep 9 at 13:43
    
@vadian thanks. Scripterror: "Microsoft Word" hast found an error: "active document" does not understand the message "save as". number -1708 from active document – Sh4kr0n Sep 9 at 14:02
    
Both syntax are supposed to work. Maybe it's an access privileges issue. You don't have permissions to write on the top level of the hard disk and you are strongly discouraged from doing that anyway. – vadian Sep 9 at 14:10
    
@vadian thanks for your answere. The applescript is on the desk and the MyHeader, TempDoc & My Save Name files are in the application - applicationfolder structur. I have all the files and applications full read and write permission given But the same error cames again. – Sh4kr0n Sep 9 at 14:25
    
the command : save as theDoc file name "OSX_El_Capitan:Documents:My Save Name.docx" is working fine for me. However, be careful when Microsoft have been used by a script with error, it sometime have strange behavior (typical example, Word no longer understand "active document"). You then need to quit Word application and launch it again. – pbell Sep 9 at 17:19

@pbell and @vadian, 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
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.