I have initially answered question How to only paste visible cells in an email body
The code I tested and posted (see below) did not include sending email. After the
But if I run the whole Sub at once, with no breakpoints, the email is sent with no pasted Excel Range in the body. What is the reason for that, and what is the solution?
The reason is pretty simple. When you use breakpoint, you are giving Excel enough time for a copy paste. SendKeys hence are very unreliable when working with other applications.
There are many ways to solve your problem. One is to give enough time for a copy paste. You can do that by using DoEvents or forcing a Wait Time. For example
SendKeys "^({v})", True
DoEvents
Or
SendKeys "^({v})", True
Wait 2 '<~~ Wait for 2 seconds
and use this sub in your code
Private Sub Wait(ByVal nSec As Long)
nSec = nSec + Timer
While nSec > Timer
DoEvents
Wend
End Sub
BTW, instead of using SendKeys you can use the RangetoHTML function by Ron de Bruin as shown HERE
EDIT
If the above doesn't work then that means SendKeys is getting executed too fast in that case, use DoEvents/Wait right after .Display as well.
.Display
DoEvents
Or
.Display
Wait 2