Email VBA - graph issue

MOB

Well-known Member
Joined
Oct 18, 2005
Messages
1,055
Office Version
  1. 365
Platform
  1. Windows
I'm using the code below to send excel ranges via email, in the body of the email.

Works fine, except it doesn't include any graphs that appear to be in that range. I assume its due to a graph not being in a cell as such?

Is there any way I can get this to include graphs? I have used a workaround by using a jpeg of the range to go in the email body, but its not visually attractive!!

TIA

Code:
Sub Emailout()

    Dim rng As Range
    Dim OutApp As Object
    Dim OutMail As Object
    
    With Application
        .EnableEvents = False
        .ScreenUpdating = False
    End With

    Set rng = Nothing
    Set rng = ActiveSheet.UsedRange

    Set OutApp = CreateObject("Outlook.Application")
    Set OutMail = OutApp.CreateItem(0)

    On Error Resume Next
    With OutMail
        .To = ""
        .CC = ""
        .BCC = ""
        .Subject = ""
        .HTMLBody = RangetoHTML(rng)
        .Display
    End With
    On Error GoTo 0

    With Application
        .EnableEvents = True
        .ScreenUpdating = True
    End With

    Set OutMail = Nothing
    Set OutApp = Nothing
End Sub
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
Lots of detail here:


Basically RangetoHTML won't be an option (the OP even used JPEGs as a workaround).

Does include code to add an active chart however.

VBA Code:
Option Explicit

Sub CopyAndPasteToMailBody()
    Dim mailApp, mail As Object
    Dim olMailItem, wEditor As Variant
    Set mailApp = CreateObject("Outlook.Application")
    Set mail = mailApp.CreateItem(olMailItem)
    mail.Display
    Set wEditor = mailApp.ActiveInspector.wordEditor
    ActiveChart.ChartArea.Copy
    wEditor.Application.Selection.Paste
End Sub
 
Upvote 0
Many thanks

As a VBA novice, where would I need to put that code for it to work in my code?
 
Upvote 0
Without testing, I'd try the below. I assume you still want the RangetoHTML data also?

Looks like they just set wEditor then copy and paste into the already displayed email.


VBA Code:
Sub Emailout()

    Dim rng As Range
    Dim OutApp As Object
    Dim OutMail As Object
    Dim wEditor As Variant
  
    With Application
        .EnableEvents = False
        .ScreenUpdating = False
    End With

    Set rng = Nothing
    Set rng = ActiveSheet.UsedRange

    Set OutApp = CreateObject("Outlook.Application")
    Set OutMail = OutApp.CreateItem(0)

    On Error Resume Next
    With OutMail
        .To = ""
        .CC = ""
        .BCC = ""
        .Subject = ""
        .HTMLBody = RangetoHTML(rng)
        .Display
    End With
    On Error GoTo 0

Set wEditor = OutApp.ActiveInspector.wordEditor
    ActiveChart.ChartArea.Copy
    wEditor.Application.Selection.Paste

    With Application
        .EnableEvents = True
        .ScreenUpdating = True
    End With

    Set OutMail = Nothing
    Set OutApp = Nothing
End Sub

[URL='https://www.mrexcel.com/board/posts/5705214/react?reaction_id=1']Like[/URL] [URL='https://www.mrexcel.com/board/threads/email-vba-graph-issue.1173425/reply?quote=5705214']Quote[/URL] [URL='https://www.mrexcel.com/board/threads/email-vba-graph-issue.1173425/reply?quote=5705214']Reply[/URL]
[URL='https://www.mrexcel.com/board/posts/5705214/report']Report[/URL]
 
Upvote 0

Forum statistics

Threads
1,213,558
Messages
6,114,297
Members
448,564
Latest member
ED38

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