Send image with VBA via Outlook

Doflamingo

Board Regular
Joined
Apr 16, 2019
Messages
238
Hi all,

I try to understand why the code to send an image which is in the excel sheet ''GrapheImage'' with the

Object of the email in the column A, the email adress in the column B and the message of the email in the column C

Here is the code

Code:
ra = ActiveWorkbook.Path
    Sheets("GrapheImage").Copy
    Application.DisplayAlerts = False
    ActiveWorkbook.SaveAs ra & "\GrapheGif.xls"
    ActiveWindow.Close
    '---  Envoi par mail
    Dim objOL As Object
    Set objOL = CreateObject("Outlook.Application")
    Dim olapp As Outlook.Application
    Dim msg As MailItem
    Set olapp = New Outlook.Application
    Set msg = olapp.CreateItem(olMailItem)
    msg.To = Range("B2")
    msg.Subject = Range("A2").Value
    msg.Body = Range("C2")
    msg.Attachments.Add Source:=ra & "\GrapheGif.xls"
    msg.Send

Any idea :) ?
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
the problem is here

ra = ActiveWorkbook.Path
Sheets("GrapheImage").Copy
Application.DisplayAlerts = False
ActiveWorkbook.SaveAs ra & "\GrapheGif.xls"
ActiveWindow.Close
'--- Envoi par mail
Dim objOL As Object
Set objOL = CreateObject("Outlook.Application")
Dim olapp As Outlook.Application
Dim msg As MailItem
Set olapp = New Outlook.Application
Set msg = olapp.CreateItem(olMailItem)
msg.To = Range("B2")
msg.Subject = Range("A2").Value
msg.Body = Range("C2")
msg.Attachments.Add Source:=ra & "\GrapheGif.xls"
msg.Send
 
Upvote 0
VBA editor replies user defined type not defined ... I don't understand why

Add the Microsoft Outlook Library:

1. From the Menu Bar, click on Tools > References…
Screen1-1.png

2. Select ‘Microsoft Outlook XX.X Object Library’ and click on ‘OK’ button
Screen2-1.png
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,021
Latest member
Justyna P

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
Back
Top