MS Word Insert Text

This has GOT to have been covered here before, but I can’t find it, so I’ll pose the question again. It’s so basic, it SHOULD be easy.

I want to insert text after a text range in Microsoft Word.

This works:

tell application “Microsoft Word”
activate
insert text “bobbly flob” at end of text object of active document
end tell

This doesn’t:

tell application “Microsoft Word”
activate
set newRange to (create range active document start 1599 end 1611)
insert text “bobbly flob” at end of text object of newRange
end tell

That range specification is definitely valid for the document in question, in fact, I got the start and end from doing a find in the doc.

I’ve tried all sorts of variations like “at end of newRange,” “at end of content of text object of newRange,” etc. Every time AS just says that Word can’t continue the insert.

What’s up here?

Thanks for your help.

Larry the O

Larry:

Try this:

insert text "bobbly flob" at after NewRange

Weirder and weirder. I tried “at end of newRange” again and it worked. The only thing I can figure is that I hallucinated having tried it before. Glad it’s Friday.

By the way, did you test that “after” command? When I tried before, text ranges didn’t like the “before” and “after” syntax. Then again, when I tried before, “at end of newRange” didn’t work, either, so what do I know?

Larry

Larry:

It is actually at after that makes this script work. You find that phrase to be useful in a number of applications when you are trying to get access to end of something (a list, a text range, etc.) I did test it out before I posted it, but I only tested these two alternatives:

insert text "bobbly flob" at NewRange
insert text "bobbly flob" at after NewRange

I set the NewRange in my document to start at 50 and end at 250 so that I could clearly see where bobbly flob ended up.

If you are interested in all the gory details of scripting Word (or Excel), click here.

Hello ALL.
I’m new to applescripting. I recently picked up the “Missing Manual” Book for Applescripting. I’ve used the examples in the chapters many times to beat the ideas and concepts of how they work in my head. I felt like I was making headway until I come across a simple example in the book that does not work. I’ve triple checked my script. I even used the script from the CD example and that doesn’t work. There have been some scripts that worked with some changes. Each time I check the publishers website for corrections the script corrections are on the site.
In chapter 4 there’s an example script that makes Word count the characters, words, and paragraphs correctly. The book has a simpler script but applescripts results are different then Words results. The code that doesn’t work is the example that should give the same count as word…Hopefully this makes sense.

the problematic code:

tell application “Microsoft Word”
set theText to the content of the text object of the front document
set numberOfCharacters to ¬
(count every character of theText)
set characterText to "Characters: " & numberOfCharacters
set numberOfWords to (count every word of theText)
set wordText to "Words: " & numberOfWords
set numberOfParagraphs to (count every paragraph of theText)
set paragraphtext to "Paragraphs: " & number of paragraphs
set dialogText to characterText & return & wordText & return & paragraphtext
display dialog dialogText
end tell

When I try to run this script I get the following error:
Applescript Error
The Variable object is not defined.

Script Editor highlights the word “object” in the first set line.
Also
the word text is blue (as an application keyword)
the word object is green (as a variable)

I appreciate any help on understanding what I’m doing wrong(and what’s wrong with the actual script from the publisher).

Mac OSX 10.4.9
Word v. X
Script Editor 2.1.1
Applescript 1.10.7