SendMail as attachment and not as link

str8hing

Board Regular
Joined
Jul 6, 2005
Messages
69
I currently have the following code to send mail but when it runs it sends the attachment as a link to the original file and not as a standalone workbook. Any ideas?:

ActiveWorkbook.SaveAs FileName:="C:\MyFiles\my new excel file.xls"
Set myOlApp = CreateObject("Outlook.Application")
Set myItem = myOlApp.CreateItem(olMailItem)
With myItem
.Recipients.Add "John Q Receiver@aol.com"
.body = "This is the message text"
.Subject = "This is my message subject"
End With
Set myAttachments = myItem.Attachments
myAttachments.Add "C:\MyFiles\my new excel file.xls", _
olByValue, 1, "My file transmission"
myItem.Send
End Sub
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Unless you have set a reference to the Outlook library olByValue will not be recognised as a constant.

It will be assigned the value 0.

I don't know why this is creating a link to the attachment but I suggest you change olByValue to 1.
 
Upvote 0
If you don't want the Outlook message (A System is trying to send something on your behalf etc)

use this:

Rich (BB code):
Sub Mailer()
'Mails without security alert
'Need reference to Outlook in the Project References
 
Dim objol As New Outlook.Application
Dim objmail As MailItem
Dim Pathname

ActiveWorkbook.SaveAs Filename:="C:\MyFiles\my new excel file.xls"
Pathname = ActiveWorkbook.FullName

Set objol = New Outlook.Application
Set objmail = objol.CreateItem(olMailItem)
    
    With objmail
        .To = "John Q Receiver@aol.com" 'enter in here the email address
      '  .cc = "whoever" 'enter in here the email address
        .Subject = "This is my message subject" '& dname
        .Body = "This is the message Text" & _
            vbCrLf & "This is more message text" & vbCrLf
        .NoAging = True
        .ReadReceiptRequested = True
        .Attachments.Add Pathname 'adds attachment to email
        .Display
    End With
    Set objmail = Nothing
    Set objol = Nothing
    
    'Wait for System to catch up and send
    Application.Wait (Now + TimeValue("0:00:04"))
    Application.SendKeys "%s"
    Application.Wait (Now + TimeValue("0:00:04"))
    
End Sub
 
Upvote 0
What do you mean?

Just change olByValue to 1.
Code:
myAttachments.Add "C:\MyFiles\my new excel file.xls", _ 
1, 1, "My file transmission"
 
Upvote 0
Hi,

I cant believe this is all working on EVERYONES PC but mine!!

Im getting an error when it gets to

Dim objol As New Outlook.Application

Im using Office 2003 with SP2

Can you help?

Im wanting to send emails to all the people in coloum A

Thanks
 
Upvote 0

Forum statistics

Threads
1,216,028
Messages
6,128,399
Members
449,447
Latest member
M V Arun

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