Inserting styled paragraph in Word 2004

I’m concatenating a bunch of Word documents into a single document, with the filename of each component document inserted just before the corresponding text. I’m able to use “insert text” to get the filename into the document, but can’t figure out how to apply a specific style to it. Here’s what I’ve tried:

tell application “Microsoft Word”
activate
tell (make new document) to repeat with this_doc in file_list
display dialog "File being added: " & this_doc giving up after 1
set this_alias to ((the_folder as string) & this_doc) as alias
– insert text (return & return & “[* " & this_doc & " ]" & return & return) at after last character
make new paragraph at after last character with data (return & return & "[
" & this_doc & " *]” & return & return) as text with properties {style:“city”}
insert file at after last character file name (this_alias as Unicode text)
end repeat
end tell

The “insert text” line, commented out, works as expected. The “make new paragraph” inserts a return, but doesn’t apply any style to it (i.e., it stays “Normal”), and inserts no text.

This Word programming is like having a root canal . . .

Hi,

you can do it with this:

tell application "Microsoft Word"
	activate
	tell (make new document) to repeat with this_doc in file_list
		display dialog "File being added: " & this_doc giving up after 1
		set this_alias to ((the_folder as string) & this_doc) as alias
		insert text (return & return & "[* " & this_doc & " *]" & return & return) at after last character -- this creates 4 paragraphs
		set style of paragraph ((count paragraphs) - 2) to "city" -- change style of the paragraph "[*...*]"
		insert file at after last character file name (this_alias as Unicode text)
	end repeat
end tell

Thanks, stefan! That worked great. Any idea why the file insertions are so slow? The first file comes in immediately, but subsequent ones drag on and on. I need to insert 15 small files, and it takes a few minutes for what I’d thought would take no more than 30 seconds.

No, I have no idea.
I also noticed it, when I tried to create a calendar sheet in Word and
inserted data with AppleScript, to work around iCal’s lousy printing capabilities :wink: