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

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
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
Hello @DanteAmor, many thanks for your help and your time on that topic :).That works :)

I don't count the times you have helped me :).

Kind regards

Doflamingo
 
Upvote 0

Forum statistics

Threads
1,213,510
Messages
6,114,048
Members
448,543
Latest member
MartinLarkin

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