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!!
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!!