Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

wesleyh

macrumors 6502
Original poster
Mar 23, 2007
432
0
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
 
Last edited:

kryten2

macrumors 65816
Mar 17, 2012
1,114
99
Belgium
Works on Leopard with Microsoft Office 2004.
 

Attachments

  • Picture 1.png
    Picture 1.png
    75.6 KB · Views: 411

wesleyh

macrumors 6502
Original poster
Mar 23, 2007
432
0
Thanks, I reinstalled word and now it works. Perhaps I didn't select the automator section of the installation previously.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.