Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Copying entire Mail message content into Excel using Applescript

I am using the code below to try and automate the copying of entire emails from my Mail app to an excel document. The code works fine, but all of the email messages are truncated to a limit of 256 characters. I presume it has something to do with the line " my SetMessage(content of aMessage, theRow, theSheet)". Does anyone know how to fix this so that the entire email message is copied over?

tell application "Microsoft Excel"

set LinkRemoval to makenewworkbook

set theSheet to active sheet of LinkRemoval

set formula of range "D1" of theSheet to "Message"

set formula of range "C1" of theSheet to "Subject"

set formula of range "B1" of theSheet to "From"

set formula of range "A1" of theSheet to "Date"

end tell


tell application "Mail"

set theRow to 2

set theAccount to "Google"

get accounttheAccount

set theMessages to messages of inbox

repeat with aMessage in theMessages

my SetDate(date received of aMessage, theRow, theSheet)

my SetFrom(sender of aMessage, theRow, theSheet)

my SetSubject(subject of aMessage, theRow, theSheet)

my SetMessage(content of aMessage, theRow, theSheet)

set theRow to theRow + 1

end repeat

end tell


on SetDate(theDate, theRow, theSheet)

tell application "Microsoft Excel"

set theRange to "A" & theRow

set formula of rangetheRange of theSheet to theDate

end tell

end SetDate


on SetFrom(theSender, theRow, theSheet)

tell application "Microsoft Excel"

set theRange to "B" & theRow

set formula of rangetheRange of theSheet to theSender

end tell

end SetFrom


on SetSubject(theSubject, theRow, theSheet)

tell application "Microsoft Excel"

set theRange to "C" & theRow

set formula of rangetheRange of theSheet to theSubject

end tell

end SetSubject


on SetMessage(theMessage, theRow, theSheet)

tell application "Microsoft Excel"

set theRange to "D" & theRow

set formula of rangetheRange of theSheet to theMessage

end tell

end SetMessage

MacBook Pro (Retina, 13-inch, Late 2013), OS X Yosemite (10.10.2)

Posted on Apr 23, 2015 2:56 PM

Reply
1 reply

Apr 23, 2015 3:09 PM in response to dan6738

The problem is that text in Excel formulas can contain only 256 characters.


Try setting the value of the cell instead of its formula. There is no need to set it to a formula (unless the text in the email message is actually a formula you want to process in Excel), and text cell values can be (virtually) any length


set value of rangetheRange of theSheet to theMessage

Copying entire Mail message content into Excel using Applescript

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.