noboffinme
Registered User.
- Local time
- Today, 21:02
- Joined
- Nov 28, 2007
- Messages
- 288
Hi
I want to attach an Excel spreadsheet to an Outlook e-mail & the below code works OK, only I find it attaches an image of the Excel icon instead of the file itself.
Looking around, I've found 2 methods to attach a file, 'AddAttachment' & 'Attachment.Add - which one is correct or is there another method to get the file itself to attach properly??
-----------------------------------------------------------
Sub send_to_outlook()
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
Dim wb As Workbook
'code creating the 'ORDER' workbook goes here
Worksheets("ORDER").Copy
Set destwb = ActiveWorkbook
destwb.SaveAs "C:\ORDER.xlsx"
destwb.Close
'send the new worksheet to e-mail
On Error Resume Next
With OutMail
.Display
.To = email@gmail.com
.CC = ""
.BCC = ""
.Subject = "Subject line"
.Body = "Hello World!"
'.Attachments.Add ActiveWorkbook.FullName
' You can add other files by uncommenting the following line.
'.Attachments.Add ("C:\ORDER.xlsx")
.AddAttachment ("C:\ORDER.xlsx")
'.Send
End With
On Error GoTo 0
Set OutMail = Nothing
Set OutApp = Nothing
I want to attach an Excel spreadsheet to an Outlook e-mail & the below code works OK, only I find it attaches an image of the Excel icon instead of the file itself.
Looking around, I've found 2 methods to attach a file, 'AddAttachment' & 'Attachment.Add - which one is correct or is there another method to get the file itself to attach properly??
-----------------------------------------------------------
Sub send_to_outlook()
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
Dim wb As Workbook
'code creating the 'ORDER' workbook goes here
Worksheets("ORDER").Copy
Set destwb = ActiveWorkbook
destwb.SaveAs "C:\ORDER.xlsx"
destwb.Close
'send the new worksheet to e-mail
On Error Resume Next
With OutMail
.Display
.To = email@gmail.com
.CC = ""
.BCC = ""
.Subject = "Subject line"
.Body = "Hello World!"
'.Attachments.Add ActiveWorkbook.FullName
' You can add other files by uncommenting the following line.
'.Attachments.Add ("C:\ORDER.xlsx")
.AddAttachment ("C:\ORDER.xlsx")
'.Send
End With
On Error GoTo 0
Set OutMail = Nothing
Set OutApp = Nothing