I want to attach a chart in the email when the user clicks on a button.
The code isn't adding the chart.
The naming is correct and I am not receiving any errors (except ones I've implemented to help test).
If ChartNameLine = "" Then
GoTo ErrorMsgs
Else
Dim xOutApp As Object
Dim xOutMail As Object
Dim xChartName As String
Dim xPath As String
Dim xChart As ChartObject
Dim xChartPath As String
On Error Resume Next
xChartName = Application.InputBox("Please Enter the Chart name: ", "KuTools for Excel", , , , , , 2)
'xChartName = ChartNameLine
Set xChart = Worksheets(.HTMLBody).ChartObjects(xChartName)
xChart.Chart.ChartArea.Copy
errorCode = 101
'If xChart Is Nothing Then GoTo ErrorMsgs
xOutApp = CreateObject("Outlook.Application")
Set xOutMail = xOutApp.CreateItem(0)
xChartPath = ThisWorkbook.path & "\" & Environ("USERNAME") & VBA.Format(VBA.Now(), "DD_MM_YY_HH_MM_SS") & ".bmp"
xPath = "<p align='Left'><img src= " / "cid:" & Mid(xChartPath, InStrRev(xChartPath, "\") + 1) & """ width = 800 height = 500> <br> <br>"
xChart.Chart.Export xChartPath
With xOutMail
.To = ToLine
.Subject = SubjectLine
.Attachments.Add xChartPath
.HTMLBody = xPath
.Display
End With
Kill xChartPath
'Set xOutMail = Nothing
'Set xOutApp = Nothing
End If
Using code from "Extend Office"