I am trying to add specific cell values from an Excel worksheet into my predefined Outlook subject line however I am struggling with the right macro code for it. Can anyone help?
My existing Macro code opens my desired workbook and selects the table but doesn't create the pivot table as I would want. When I do F8 it shows the error comes at line: Range("Table2[#All]").Select –
Here's the code that I am using to create an Outlook email and copy specific table and chart from an Excel worksheet:
Sub Open_Outlook_and_Create_Email()
'open outlook
Dim oOutlook As Object
Set oOutlook = CreateObject("Outlook.Application")
'open Email
Dim oEmail As Object
Set oEmail = oOutlook.CreateItem(o1MailItem)
With oEmail
.To = "abcstringreports@gmail.com"
.Subject = "ABC Flash Report 2018-2-5: ABC Occ. 99% / AB (44,11)
-40.6% / BC (49,3,17,2,0,12) -1.2% / CD (9,0) -37.4% / DE (0,12,0)
3.7% / EF (11,8) -30.6% / FH (14,6) -3.6% / IJ (4,2) -69.5%"
.Body = ""
.Display
Dim oOutlookInspect As Outlook.Inspector
Dim oWordDoc, oWordDoc1 As Word.Document
Dim oChartobj As ChartObject
Set oChartobj = ActiveSheet.ChartObjects("Chart 7")
oChartobj.Chart.ChartArea.Copy
Set oOutlookInspect = .GetInspector
Set oWordDoc = oOutlookInspect.WordEditor
Set oWordRng = oWordDoc.Application.ActiveDocument.Content
oWordRng.InsertAfter " " & vbNewLine
oWordRng.Collapse Direction:=wbCollapseEnd
oWordRng.Paste
Set oOutlookInspect = .GetInspector
Set oWordDoc1 = oOutlookInspect.WordEditor
ActiveSheet.Range("ProjData").Copy
Set oWordRng1 = oWordDoc1.Application.ActiveDocument.Content
oWordRng1.InsertAfter " " & vbNewLine
oWordRng1.Collapse Direction:=wbCollapseEnd
oWordRng1.Paste
'.Send
End With
'Clear the objects
Set oEmail = Nothing
Set oOutlook = Nothing
Errhandler:
End Sub
More specifically, I am looking for a Macro code that can update the percentages (%) in my Outlook email subject line with particular cell values from an Excel worksheet.
Look forward to your input.
Thanks, K
I tried the above Macro and the result is as expected that it open the Outlook email and copies the relevant chart and table from an Excel file. However, it doesn't copy and paste the relevant cell values from the Excel worksheet into the Outlook email subject line.