I have been racking my brain trying to find a solution to this for days. I have compiled an applescript to loop through a word mailmerge, save each record as a html file and then read the html file s utf8 to be used in a outlook email body.
Where I am getting stuck is the reading of the created html file as utf8. I keep getting the following error:
"error “Microsoft Word got an error: End of file error.” number -39 from file “Macintosh HD:Users:Tiana:Desktop:BodyFiles:1.html”
I know that if I can read the html file correctly as utf8 it will work (I’ve testing this script using a pre-prepared html file and bypassing the mail merging). Here is my script below:
tell application "System Events"
tell the user domain
set thertfname to ((the path of the desktop folder) as text) & "BodyFiles:" & theRecord & ".rtf"
set thehtmlname to ((the path of the desktop folder) as text) & "BodyFiles:" & theRecord & ".html"
end tell
end tell
-- now do the merge for that one record, save the result and close
set the first record of theDataSource to theRecord
set the last record of theDataSource to theRecord
execute data merge theDataMerge
save as active document file name thertfname file format format rtf
close active document
set b to thertfname
do shell script "textutil -convert html " & b
set theFilePath to thehtmlname
if characters -5 thru -1 of theFilePath as string is ".html" then
set theFileHandle to (open for access file theFilePath)
set someData to (read theFileHandle as «class utf8»)
close access theFileHandle
end if
Cross posted here: http://stackoverflow.com/questions/41864176/applescript-read-html-file-as-utf-8