HELP!!!~Macro to send email from outlook with pictures!!~

lwrgl

New Member
Joined
Jul 17, 2013
Messages
4
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:

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
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.

Andrew Poulsom

MrExcel MVP
Joined
Jul 21, 2002
Messages
73,092
Why don't you copy the two ranges to a new worksheet so that it is a contiguous range and put that in the body of the Email?
 
Upvote 0

lwrgl

New Member
Joined
Jul 17, 2013
Messages
4
Why don't you copy the two ranges to a new worksheet so that it is a contiguous range and put that in the body of the Email?

Dear Andrew, thank you so much for the reply!
Because my table has 4 rows, 1st & 3rd rows are for contents, and I need to paste the 2 ranges as picture on the 2nd & 4th row........
 
Upvote 0

Forum statistics

Threads
1,191,025
Messages
5,984,195
Members
439,877
Latest member
kellylet

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top