Send excel table in the content of Gmail by VBA

KalvinLam

New Member
Joined
Sep 23, 2014
Messages
1
Dear Sir, I'm now trying to use excel VBA to send table via Gmail. However, I face a problem that i don't not know how to send range of selected cell in excel to Gmail.

my VBA coding as follows:-


Sub Macro3()
'
' Macro3 Macro
' 宏由 kalvin.lam 录制,时间: 2014/9/22
'
Dim Mail As New Message
Dim Config As Configuration
Set Config = Mail.Configuration


Config(cdoSendUsingMethod) = cdoSendUsingPort
Config(cdoSMTPServer) = "smtp.gmail.com"
Config(cdoSMTPServerPort) = 25
Config(cdoSMTPAuthenticate) = cdoBasic
Config(cdoSMTPUseSSL) = True
Config(cdoSendUserName) = "my email account"
Config(cdoSendPassword) = "my email password!"
'Config(cdoSendPassword) = InputBox("Please enter your password")
Config.Fields.Update


Mail.To = "recipient email account"
Mail.From = Config(cdoSendUserName)
Mail.Subject = Sheet1.Range("B1")
Mail.HTMLBody = "<b>How ar u<b>"
Mail.Body = Sheet1.Range ("B5:F12")==> how to coding that selected range of cell can be automatically shown in the content of GMail.


'Mail.AddAttachment ""


On Error Resume Next


Mail.Send


If Err.Number <> 0 Then
MsgBox Err.Description, vbCritical, "There was an error"
Exit Sub
End If


MsgBox "Your email has been sent!", vbInformation, "sent"


End Sub
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.

Forum statistics

Threads
1,214,990
Messages
6,122,625
Members
449,093
Latest member
catterz66

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