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
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