Help scripting MSWord

This works fine on my iMac. it doesn’t work on my MacbookPro. both are running Mountain Lion and the same version of MS Office.

I get an applescript error that states Microsoft Word got an error: Can’t make class document

Here is my code:

tell application “Microsoft Word”
activate
delay 3

if not (exists document 1) then
	make new document
end if
set left margin of page setup of document 1 to (inches to points inches 0.5)
set top margin of page setup of document 1 to (inches to points inches 0.5)
set right margin of page setup of document 1 to (inches to points inches 0.5)
set bottom margin of page setup of document 1 to (inches to points inches 0.5)
set header distance of page setup of document 1 to (inches to points inches 0)
set footer distance of page setup of document 1 to (inches to points inches 0)
paste special text object of document 1 data type paste text
tell text object of document 1 to set font size of font object to 12.0


auto format text range text object of document 1
tell application "Finder" to delete file ((path to documents folder as text) & "huddle.doc")
save document 1 in ((path to documents folder as text) & "huddle.doc") as format flat document
delay 2
quit

end tell

I can’t figure out what is wrong.

Word is notoriously flaky to script. It’s the MS way.

Your script works fine on my MB Pro (early 2011 - OSX 10.8.3) running Word 2011 (14.2.3). Even so, I changed a few things that have worked for me in the past:

tell application "Microsoft Word"
	activate
	delay 3
	
	if not (exists document 1) then
		set newDoc to make new document
	else
		set newDoc to document 1
	end if

	set left margin of page setup of newDoc to (inches to points inches 0.5)
	set top margin of page setup of newDoc to (inches to points inches 0.5)
	set right margin of page setup of newDoc to (inches to points inches 0.5)
	set bottom margin of page setup of newDoc to (inches to points inches 0.5)
	set header distance of page setup of newDoc to (inches to points inches 0)
	set footer distance of page setup of newDoc to (inches to points inches 0)
	paste special text object of newDoc data type paste text
	tell text object of newDoc to set font size of font object to 12.0
	
	
	auto format text range text object of newDoc
	
	tell application "Finder" to delete file ((path to documents folder as text) & "huddle.doc")
	save newDoc in ((path to documents folder as text) & "huddle.doc") as format flat document
	close every document
	
	delay 2
	quit
end tell

Good Luck,

Thanks Craig. I tired it but got the same error: cannot make new file. It certainly is flakey since it works on one machine and not on another.

Check one more thing: Fire up Word on the machine that is giving you the problem, and make sure that the introductory screen does NOT show. There is a way (in Preferences, I think) to suppress that behavior, which can also be a factor.

Have you tried the script (minus the activate) while Word is active?