Text Alignment in Word 2008

What I’m trying to do seems fairly simple, align the text I’m trying to import into Word. But, I’m an AS newbie, so I can’t seem to get it to work. Here’s what I have…


tell application "Microsoft Word"
	activate
	set fSel to font object of selection
	set name of fSel to "Times New Roman"
	set bold of fSel to true
	set italic of fSel to true
	set font size of fSel to 16
	set alignment of fSel to paragraph align center
	type text selection text "Text_Export"
end tell

It returns an error though.
I haven’t seen much of any solid help for using AppleScript with Office 2008, anybody have recommendations?

jon

Hi,

set alignment of fSel to align paragraph center

:wink:

the problem is, alignment is no property of a font object.
Alignment can be a property of word art format, row options, paragraph format, page number, row, horizontal line format or tab stop

Sorry, I’m probably more of a newbie than I thought. I’m working with a blank document that I’m inserting text from another program, how would I set the next line I want to import to be center aligned? I understand that I need to set the paragraph format of that line to be centered but not how to write that in AS. Thanks for the help.

jon

try this


tell application "Microsoft Word"
	activate
	tell font object of selection
		set name to "Times New Roman"
		set bold to true
		set italic to true
		set font size to 16
	end tell
	tell paragraph format of selection to set alignment to align paragraph center
	type text selection text "Text_Export"
end tell

Thank you. That is awesome.

jon

No, I just read the dictionary :wink:

I guess my problem is dictionary reading then, cause I couldn’t figure it out from that!

little “investigation description”:

open dictionary of MS Word

¢ search for selection, klick the first result (with description: “Returns the selection object”)
you’ll get selection as property of application
¢ click on selection object
you’ll get all properties and elements of selection (object)
¢ click on font of font object
you will see, there is no alignment property

¢ search for alignment, klick the first result of Text Suite (you want to handle text)
you’ll get alignment as element of paragraph format
and you’ll see also the enumerations (align paragraph left/align paragraph center/align paragraph right/align paragraph justify/align paragraph distribute)

go back to selection object. There is a property paragraph format, voila