How Can I Modify This Code To Work For Two Charts?

aedctalk

Board Regular
Joined
Oct 9, 2010
Messages
156
I'd like to insert two charts into the body instead of one.. using this code. i've tried duplicating Fname everywhere and creating Fname2

It works for attachments doing it that way. But for some reason i can't get two images in the body..

:(

how could i modify so it would play two different chart images in the body?

Thank you soooooo much!


Code:
    Dim OutApp As Object
    Dim OutMail As Object
    Dim FName As String
    Dim rng As Range

    Set OutApp = CreateObject("Outlook.Application")
    Set OutMail = OutApp.CreateItem(0)
    'fill in the file path/name of the gif file
    FName = Environ$("temp") & "\Theatre_Charts.gif"

    'if you hold down the CTRL key when you select the chart
    'in 2000-2010 you see the name in the name box(formula bar)
    ActiveWorkbook.Worksheets("Theatre-Tracker").ChartObjects("223").Chart.Export _
            Filename:=FName, FilterName:="GIF"

    On Error Resume Next
    With OutMail
        .To = Worksheets("Configuration").Range("J10")
        .CC = ""
        .BCC = ""
        .Subject = "Daily Theatre Tracker Summary"
        
        .HTMLBody = "<BODY><img src='" & FName & "'></BODY>"
        .Attachments.Add FName
        
        
        .Display   'or use .Display
    End With
    On Error GoTo 0
    Kill FName
   
    Set OutMail = Nothing
    Set OutApp = Nothing
 

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)
HTML:
    Dim OutApp As Object
    Dim OutMail As Object
    Dim FName1 As String, FName2 As String
    Dim rng As Range

    Set OutApp = CreateObject("Outlook.Application")
    Set OutMail = OutApp.CreateItem(0)
    'fill in the file path/name of the gif file
    FName1 = Environ$("temp") & "\Theatre_Charts1.gif"
    FName2 = Environ$("temp") & "\Theatre_Charts2.gif"

    'if you hold down the CTRL key when you select the chart
    'in 2000-2010 you see the name in the name box(formula bar)
    ActiveWorkbook.Worksheets("Theatre-Tracker").ChartObjects("223").Chart.Export _
            Filename:=FName1, FilterName:="GIF"
    ActiveWorkbook.Worksheets("Theatre-Tracker").ChartObjects("224").Chart.Export _
        Filename:=FName2, FilterName:="GIF"
            
    With OutMail
        .To = Worksheets("Configuration").Range("J10")
        .CC = ""
        .BCC = ""
        .Subject = "Daily Theatre Tracker Summary"
        .HTMLBody "<H3><B>Chart 1</B></H3>" & _
                  "<img src=" & FName1 & " alt=""Chart 1""/><br><br>" & _
                  "<H3><B>Chart 2</B></H3>" & _
                  "<img src=" & FName2 & " alt=""Chart 2""/><br><br>"

        '.Attachments.Add FName1
        '.Attachments.Add FName2
        
        .Display   'or use .Display
    End With
   
    Set OutMail = Nothing
    Set OutApp = Nothing
 
Last edited:
Upvote 0
Thanks so much. I was able to get it working! Really appreciate the help.

I was wondering if there might be someone willing to test this code though because i'm having one issue.


Its built to put the image in attachment and into the body of the email. It does both (i have it to display the email first)... So i see it when the email is displayed.

but once email is sent the images in the body appear broken.


I was wondering if someone could test this and help me figure out if this is an error i have in the coding? Or a setting in my email program?

I have the email program set to accept HTML..

Thanks look forward to hearing back.
 
Upvote 0

Forum statistics

Threads
1,224,547
Messages
6,179,436
Members
452,915
Latest member
hannnahheileen

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