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

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
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,223,910
Messages
6,175,320
Members
452,635
Latest member
laura12345

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