I am trying to send email using VBA through GMAIL by using internet explorer. I have data in Range("A1:AL4") and i want to put this data in gmail's compose body. if I try with single range like on A1 my code work but it does not work with multiple cells.
'Insert Email content
IE.document.querySelector("div[class*= LW-avf]").innerText = Sheets("Sheet1").Range("A1:AL4").Value
I want the whole data from A1 to AL4 in the email body.
You could try something like this:
Dim cell As Range
Dim sht As Worksheet
Dim emailBody As String
emailBody = ""
Set sht = ThisWorkbook.Worksheets("Sheet1")
For Each cell In sht.Range("A1:AL4").cells
emailBody = emailBody & cell.Value
Next cell
So basically you concatenate all strings in your range and form a single big string which you can then assign to your email's body.
Of course, if you need spaces or linebreaks between the contents of each cell you can do that:
emailBody = emailBody & " " & cell.Value
or
emailBody = emailBody & vbNewLine & cell.Value
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.