Dear all,
please help me...I'm trying to send a email from excel macro. And I got stopped by a small step, please help! Explanations below.
My codes are below:
please help me...I'm trying to send a email from excel macro. And I got stopped by a small step, please help! Explanations below.
My codes are below:
Code:
Sub abc()
Dim myolapp As Object
Dim myitem As Object
Set myolapp = CreateObject("Outlook.Application")
myolapp.Session.Logon
'create email from a template where has a table inside.
Set myitem = myolapp.CreateItemFromTemplate("C:\Users\abc\AppData\Roaming\Microsoft\Templates\test.oft")
With ActiveSheet
Set rngSubject = .Range("Q3")
Set rngBody = .Range(.Range("B2"), .Range("L13")) 'This is the first part I want to copy and paste into my email table
End With
rngBody.Copy
myitem.Subject = rngSubject
myitem.Display
SendKeys "{DOWN}{DOWN}{DOWN}%HVS{UP}~", True 'This will copy my 1st part to email as picture
Set myolapp = Nothing
Set myitem = Nothing
Set rngBody = Nothing
'Now I want to go back to excel to copy the second part, and change to email window to paste in 2nd table as picture
Windows("test.xlsb").Activate
Range("B16:L27").Select
Selection.Copy
Windows(rngSubject & " - Message(HTML).oft").Activate 'But this step failed. also the email copied the 2nd part and pasted in email in my 1st part.
SendKeys "{DOWN}{DOWN}{DOWN}%HVS{UP}~", True
End Sub