Hi,
I want to send mail with the active excel file as attachment..
Eg:cell A1- the mail address is inputted..
Whenever the user clicks it should send..
Through macro
Hi,
I want to send mail with the active excel file as attachment..
Eg:cell A1- the mail address is inputted..
Whenever the user clicks it should send..
Through macro
Trevor Shuttleworth - Retired Excel/VBA Consultant
I dream of a better world where chickens can cross the road without having their motives questioned
'Being unapologetic means never having to say you're sorry' John Cooper Clarke
try
from sintek send email using gmail
modified to attached current excel file
set reference to Microsoft CDO for Windows2000 library
needs 2-step authentication disabled and less secure apps enabled in the gmail settings
![]()
Option Explicit Sub Send_Email() Dim NewMail As CDO.Message Set NewMail = New CDO.Message ' ! To get these details you can get on Settings Page of your Gmail Account................... NewMail.Configuration.Fields.Item _ ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True NewMail.Configuration.Fields.Item _ ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1 NewMail.Configuration.Fields.Item _ ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.gmail.com" NewMail.Configuration.Fields.Item _ ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25 NewMail.Configuration.Fields.Item _ ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 NewMail.Configuration.Fields.Item _ ("http://schemas.microsoft.com/cdo/configuration/sendusername") = "whateveryourgmailemailis" NewMail.Configuration.Fields.Item _ ("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "yourpassword" NewMail.Configuration.Fields.Update With NewMail .To = Range("A1").Value .From = "whatever@gmail.com" '---your email address .Subject = "Whatever you like" .HTMLBody = "Dear Whoever " & vbNewLine & vbNewLine & "Herewith an email with file attached." .AddAttachment ThisWorkbook.Path & "\" & ThisWorkbook.FullName & ".xlsx" .send End With Set NewMail = Nothing End Sub
Last edited by k1dr0ck; 12-09-2019 at 05:01 AM.
@k1dr0ck thank you for sharing your code.
When using library references 'Early Binding' is used:
The same thing can be accomplished without using library references using 'Late Binding:'.![]()
Dim NewMail As CDO.Message Set NewMail = New CDO.Message
Reference: http://peltiertech.com/Excel/EarlyLateBinding.html![]()
Dim NewMail As Object Set NewMail = CreateObject("CDO.Message")
I prefer 'Late Binding' because Library References are NOT required. Microsoft and many pros prefer 'Early Binding'.
Pros of Early Binding:
a. Code generally runs slightly faster
b. You can take advantage of VBA 'Intellisense' during development
c. Constants from the Library Reference are available
Pros of Late Binding:
a. Library references not required
b. You don't have to worry about having the wrong version of the Library Reference, especially when a future version of Excel becomes current.
Cons of Late Binding:
a. Intellisense not available for Library Items
b. Library Constants are NOT AVAILABLE and must be explicitly defined (e.g. Outlook constant: 'Public Const olMail = 43')
Lewis
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks