Resolved Applescript : close word document (office 2011)

Discussion in 'Mac Programming' started by wesleyh, Jan 23, 2013.

  1. wesleyh, Jan 23, 2013
    Last edited: Jan 26, 2013

    macrumors 6502

    Joined:
    Mar 23, 2007
    #1
    i'm simply trying to close a document (without quitting word), but this does not work.

    I've tried :

    Code:
    close documents saving no
    close active document
    close document 1
    but none of this is working..

    The error I get (on the close line) is:

    Code:
    Microsoft Word got an error: The object you are trying to access does not exist
    
    Here is a simplified script. Anyone have any ideas? All examples online seem to use this syntax, not sure if anything changed in the mac office 2011 version? Or is it just me? Does this code work on your system?

    Thanks in advance.

    Code:
    set input to {POSIX path of "/Users/Wesley/Desktop/test.doc"}
    
    --ENABLE GUI SCRIPTING
    tell application "System Events"
    if UI elements enabled is false then set UI elements enabled to true
    end tell
    
    --RUN THE GUISCRIPT
    set pdfSavePath to POSIX path of (choose folder with prompt "Set destination folder")
    repeat with x in input
    display dialog x
    
    tell application "Microsoft Word"
        activate
        open x
        set theActiveDoc to the active document
    
        close theActiveDoc saving no
    
        return
        end tell
     end repeat
    
     
  2. macrumors 6502a

    Joined:
    Mar 17, 2012
    Location:
    Belgium
    #2
    Works on Leopard with Microsoft Office 2004.
     

    Attached Files:

  3. thread starter macrumors 6502

    Joined:
    Mar 23, 2007
    #3
    Thanks, I reinstalled word and now it works. Perhaps I didn't select the automator section of the installation previously.
     

Share This Page