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
 

Some videos you may like

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.

Watch MrExcel Video

Forum statistics

Threads
1,109,042
Messages
5,526,420
Members
409,701
Latest member
nitmani

This Week's Hot Topics

Top