germanpbv
New Member
- Joined
- Jan 25, 2020
- Messages
- 4
- Office Version
- 365
- 2019
- 2016
- 2013
- Platform
- Windows
- Web
Hello everyone!! Hopefully somebody can help me!
I am using VBA to create an email from Excel that includes in the body of the message a table that I am selecting as an specific range.
The problem that I have is:
You can understand better with the image below. Also I am copying the code I am using.
Code:
Everything works well creating the email. The problem is the table I am copying brings me all the rows... not only the ones that have data.
Thank you very much!
I am using VBA to create an email from Excel that includes in the body of the message a table that I am selecting as an specific range.
The problem that I have is:
I have not been able to select just the dynamic range that contains values.
It automatically select all the range that contains also formulas even if the value is empty.
You can understand better with the image below. Also I am copying the code I am using.
Code:
VBA Code:
Sub sentemails()
Dim Outlook As Object
Dim newEmail As Object
Set Outlook = CreateObject("Outlook.Application")
Set newEmail = Outlook.CreateItem(0)
With newEmail
.BodyFormat = 2
.Display
.HTMLBody = Sheet5.Range("B3").Text & "<br>" & Sheet5.Range("B4").Text & "<br>" & Sheet5.Range("B5").Text & "<br>" & .HTMLBody
.To = Sheet2.Range("E1").Text
.CC = Sheet5.Range("B1").Text
.Subject = Sheet5.Range("B2").Text
Dim xInspect As Object
Dim pageEditor As Object
Set xInspect = newEmail.GetInspector
Set pageEditor = xInspect.WordEditor
Sheet2.Range("A4:Y50").Copy
pageEditor.Application.Selection.Start = Len(.Body)
pageEditor.Application.Selection.End = pageEditor.Application.Selection.Start
pageEditor.Application.Selection.Paste
Set pageEditor = Nothing
Set xInspect = Nothing
'.Send
End With
Set newEmail = Nothing
Set Outlook = Nothing
End Sub
Everything works well creating the email. The problem is the table I am copying brings me all the rows... not only the ones that have data.
Thank you very much!