Using Applescript to to create and format a document in MS Word

P

PhilMaker Pro

I'm using Applescript on OS X 3.9 to create and format a MS Word v11
document using FileMaker Pro v6 to supply contract copy. After spending
considerable time searching the Word/Applescript reference document
from Microsoft I've come up with a nearly working script that uses
formatting tags (of my own creation) that I placed in the contract copy
within FileMaker to apply various formatting such as built-in styles,
various paragraph formatting, and special/hidden character replacement.


I want to avoid hard coding my search-replace routine with the style
format codes I've created. Instead, I use a table in FileMaker that
contains the codes, the Word style names as they need to be referenced
in Applescript, and a field that directs my Applescript to use a the
appropriate subroutine to search for my tags and replace them with
whatever type of formatting or invisible/special characters I'm trying
to apply. By doing this, I can simply add formatting records to my
FileMaker table with little or no need to modify my Applescript.

The problem, however, is that Word's Applescript commands for setting
Find and Replacement object properties won't seem to allow me to use a
variable to assign a Word built-in style name that corresponds to
whatever formatting tag my copy contains. Here's the applicable portion
of the code I've written:
__________________________________

-- Search and Replace in word to apply formatting based on format tags
applied to copy and ¬
-- defined in BIS_CodeXReference.fp5

repeat with i from 1 to x
set searchReplace to item i of dbFormatInfoList
set searchType to fldCodeSubType of searchReplace as string
set searchValue to fldCode of searchReplace as string
set replaceValue to fldLiteral of searchReplace as string
set replaceStyle to "style " & replaceValue
if searchType is "Style" then

-- Applies paragraph styles and eliminates formatting tag

set content of theFind to searchValue
set content of replacement of theFind to "[~]"

-- ****BELOW is the problem expression****

set style of replacement of theFind to (replaceStyle)
else
if searchType is "Replace" then...

-- More if...else branches follow, then:

end if
execute find theFind wrap find find continue replace replace all with
match forward
end repeat
____________________________________

If I change the "set style" expression to read: "set style of
replacement of theFind to style body text" it works fine--except of
course that I don't' want all of my copy styled as body text!

So how can I dynamically create this expression to reflect the
appropriate style without creating having to hard code a separate
complete set expression for each tag/style combination that I need to
apply--a workable, but inelegant solution that will require I modify
the script every time I want to enable the application of a new
potential built-in style.

thanks in advance for any suggestions offered.

Phil
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top