I am wanting to send Excel sheet 1 by Email (Gmail) . Address is in A1, Copy Address is in A2, Subject is A3. I am using Excel 2016. Thanks.
Send Email Using Gmail
- johndrew982
- Thread is marked as Resolved.
-
-
-
-
I only changed the email address to mine. Now I get send using configuration value is invalid. It highlights .send in yellow.
Code
Display MoreSub CDO_Mail_Small_Text() Dim iMsg As Object Dim iConf As Object Dim strbody As String Dim Flds As Variant Set iMsg = CreateObject("CDO.Message") Set iConf = CreateObject("CDO.Configuration") ' iConf.Load -1 ' CDO Source Defaults ' Set Flds = iConf.Fields ' With Flds ' .Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 ' .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "Fill in your SMTP server here" ' .Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25 ' .Update ' End With strbody = "Hi there" & vbNewLine & vbNewLine & _ "This is line 1" & vbNewLine & _ "This is line 2" & vbNewLine & _ "This is line 3" & vbNewLine & _ "This is line 4" With iMsg Set .Configuration = iConf .To = "[email protected]" .CC = "" .BCC = "" .From = """John"" <[email='[email protected]'][/email]>" .Subject = "Important message" .TextBody = strbody .Send End With Set iMsg = Nothing Set iConf = Nothing Set Flds = Nothing End Sub
-
Welcome to the Forum. Please read the Forum Rules to understand how the Forum works and why I have added Code Tags to your post
All VBA code posted in the forum must be wrapped in code tags, which you omitted, including single-line code snippets.Be sure to use them in future posts.
How to use code tags
Just highlight all of the code and press the <> in the post menu above button to add the code tags.
Thanks.
-
Attach your workbook with the code in.
-
Here is the code I used. I changed the To: addy to [email protected]. When I dubug it has .SEND hilighted in yellow.
Code
Display MoreSub CDO_Mail_Small_Text() Dim iMsg As Object Dim iConf As Object Dim strbody As String Dim Flds As Variant Set iMsg = CreateObject("CDO.Message") Set iConf = CreateObject("CDO.Configuration") ' iConf.Load -1 ' CDO Source Defaults ' Set Flds = iConf.Fields ' With Flds ' .Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 ' .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "Fill in your SMTP server here" ' .Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25 ' .Update ' End With strbody = "Hi there" & vbNewLine & vbNewLine & _ "This is line 1" & vbNewLine & _ "This is line 2" & vbNewLine & _ "This is line 3" & vbNewLine & _ "This is line 4" With iMsg Set .Configuration = iConf .To = "[email protected]" .CC = "" .BCC = "" .From = [attach='1232706'][/attach][attach='1232706'][/attach][attach='1232706'][/attach][attach='1232706'][/attach][attach='1232706'][/attach] .Subject = "Important message" .TextBody = strbody .Send End With Set iMsg = Nothing Set iConf = Nothing Set Flds = Nothing End Sub
-
Please use code tags.
Please use Code Tags, read the Forum Rules to see how and why.
-
Perhaps this Send an email through Gmail using VBA site can/will shed more light on achieving what you're wanting.
-
You might need to go to https://myaccount.google.com/security?pli=1#connectedapps from your browser and turn on the “Allow less secure apps” option.
Participate now!
Don’t have an account yet? Register yourself now and be a part of our community!