Email from Excel using AppleScript (for Excel 2008)

esneaker

New Member
Joined
Feb 1, 2015
Messages
11
Greetings!

I created a code using VBA that allows you to send a range of cells as an attachment in Excel 2011. It also allows you to send the mail via Applemail and Outlook (help on one would be enough!). This code was modified from Ron De Bruin's code. Is there a way to utilize this function using AppleScript for Excel 2008?

A sample of my code is below.

Dim Source As Range
Dim Destwb As Workbook
Dim wb As Workbook
Dim TempFilePath As String
Dim TempFileName As String
Dim FileExtStr As String
Dim FileFormatNum As Long

If Val(Application.Version) < 14 Then Exit Sub

Set Source = Nothing
On Error Resume Next
Set Source = Range("A96:F134").SpecialCells(xlCellTypeVisible)
On Error GoTo 0

If Source Is Nothing Then
MsgBox "The source is not a range or the sheet is protected, " & _
"please correct and try again.", vbOKOnly
Exit Sub
End If

With Application
.ScreenUpdating = False
.EnableEvents = False
End With

Set wb = ActiveWorkbook
Set Destwb = Workbooks.Add(xlWBATWorksheet)

Source.Copy
With Destwb.Sheets(1)
.Cells(1).PasteSpecial Paste:=8
.Cells(1).PasteSpecial Paste:=xlPasteValues
.Cells(1).PasteSpecial Paste:=xlPasteFormats
.Cells(1).Select
Application.CutCopyMode = False
End With

'Save format and extension
FileExtStr = ".xlsx": FileFormatNum = 52

'Or if you want it in xls format, use:
'FileExtStr = ".xls": FileFormatNum = 57


'Save the new workbook/Mail it/Delete it
'If you want to change the file name then change only TempFileName
TempFilePath = MacScript("return (path to documents folder) as string")
TempFileName = wb.Name & " " & Format(Date, "MMM-YYYY")

With Destwb
.SaveAs TempFilePath & TempFileName & FileExtStr, FileFormat:=FileFormatNum
MailFromMacwithOutlook bodycontent:="Hi there", _
mailsubject:="Incidental Tracker for" & Format(Date, "MMM-YYYY"), _
toaddress:="yum.yum@mail.com", _
ccaddress:="", _
bccaddress:="", _
attachment:=.FullName, _
displaymail:=True
.Close SaveChanges:=False
End With

KillFileOnMac TempFilePath & TempFileName & FileExtStr

With Application
.ScreenUpdating = True
.EnableEvents = True
End With
End Sub




Thank you ahead of time for your assistance and help!!
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes

Forum statistics

Threads
1,214,644
Messages
6,120,709
Members
448,983
Latest member
Joaquim_Baptista

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top