Search and replace in Word document using Filemaker data

I am trying to get around merging files.
I have a database of Matters in filemaker pro advanced.
I have created a script in the matters file which uses applescript to open a word template file, rename it according to the name of the record I ran the script from and save it with the new name. This part of the script works fine.
It is implemented by using a global field with the filename in it and setting a variable in applescript by reference to the global field: “get cell”

The new file is a letter - I want to be able to extract the name of the matter from the filemaker database and place it at a specific location in the word document.
My plan is to have a unique word on the document and to search for that word and replace it with a variable in applescript derived from a field in filemaker.

I want to do this, if it can be done, without closing the document I have just created.

after much trial and error i am getting the feeling that I may not be able to do this unless i close the document first and/or that you cant use defined variable in the search replace “command” (if that is what it is - forgive me I am not a programmer or anything)

Thanks in anticipation.

:smiley:
Solved

set thename to cell “documentname”
set {day:d, month:m, year:y} to (current date)
set theDate to (d," “, m,”, ", y) as string
set thefirm to cell “Firmname”
set theaddress to cell “Address”
set theref to cell “Reference”
set thematter to cell “Mattername”

tell application “Microsoft Word”
activate
open “Macintosh HD:Fees_Program:Documents:Templates:Letter.dot”
save as active document file name “Macintosh HD:Fees_Program:Documents:My Documents:”& thename
end tell

tell application “Microsoft Word”
set findRange to find object of selection
tell findRange
execute find find text “Date” replace with thedate replace replace all
end tell
end tell

tell application “Microsoft Word”
set findRange to find object of selection
tell findRange
execute find find text “Firm” replace with thefirm replace replace all
end tell
end tell

tell application “Microsoft Word”
set findRange to find object of selection
tell findRange
execute find find text “Address” replace with theaddress replace replace all
end tell
end tell

tell application “Microsoft Word”
set findRange to find object of selection
tell findRange
execute find find text “zf” replace with theref replace replace all
end tell
end tell

tell application “Microsoft Word”
set findRange to find object of selection
tell findRange
execute find find text “Matter” replace with thematter replace replace all
end tell
end tell