Simple Word script help

Hello.

I’m new to scripting and am looking for something that I think is really basic. I just want to tell Word to delete all the text from the current document, then insert one line of text, then insert a second line of text two lines below that. Something like this (only with the correct syntax):

Tell application “Microsoft Word”
delete all text of current document
insert text “I am the first line” at beginning of current document
hit return
hit return
insert text “I am the second line”
end tell

Any help would be greatly appreciated.

Thanks,

  • Bruce

How about this code (tested with MS Word 2004)?


tell application "Microsoft Word"
	tell active document
		set content of text object to ""
		set content of text object to ("I am the first line" & return & return & "I am the second line")
	end tell
end tell

Also see this excellent article written by Ben Waldie.

Perfect! Thanks so much.

  • Bruce