Here is my code; I need help fixing this error code. I want to run the code once and have my pivot and chart table shown.
<code>Sub Outlook_Email()
Dim oOutlook As Object
Set oOutlook = CreateObject("Outlook.Application")
Dim oEmail As Object
Set oEmail = oOutlook.CreateItem(0)
With oEmail
.To = "[email protected]"
.CC = "[email protected]; [email protected]"
.Body = "Hi Team, this is a sample email"
.Display
Dim oOutlookInspect As OutLook.Inspector
Dim oWordDoc, oWordDoc1 As Word.Document
Dim oChartobj As ChartObject
For Each oChartobj In ActiveSheet.ChartObjects
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
Next
Set OutAppInspect = .GetInspector
Set oWordDoc1 = OutAppInspect.WordEditor
ActiveSheet.Range("StockData").Copy
Set oWordRng1 = oWordDoc1.Application.ActiveDocument.Content
oWordRng1.InsertAfter " " & vbNewLine
oWordRng1.Collapse Direction:=wbCollapseEnd
oWordRng1.Paste
End With
Set oEmail = Nothing
Set oOutlook = Nothing
End Sub
</code>
<code>Sub Outlook_Email()
Dim oOutlook As Object
Set oOutlook = CreateObject("Outlook.Application")
Dim oEmail As Object
Set oEmail = oOutlook.CreateItem(0)
With oEmail
.To = "[email protected]"
.CC = "[email protected]; [email protected]"
.Body = "Hi Team, this is a sample email"
.Display
Dim oOutlookInspect As OutLook.Inspector
Dim oWordDoc, oWordDoc1 As Word.Document
Dim oChartobj As ChartObject
For Each oChartobj In ActiveSheet.ChartObjects
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
Next
Set OutAppInspect = .GetInspector
Set oWordDoc1 = OutAppInspect.WordEditor
ActiveSheet.Range("StockData").Copy
Set oWordRng1 = oWordDoc1.Application.ActiveDocument.Content
oWordRng1.InsertAfter " " & vbNewLine
oWordRng1.Collapse Direction:=wbCollapseEnd
oWordRng1.Paste
End With
Set oEmail = Nothing
Set oOutlook = Nothing
End Sub
</code>
Sub Outlook_Email()
Dim oOutlook As Object
Set oOutlook = CreateObject("Outlook.Application")
Dim oEmail As Object
Set oEmail = oOutlook.CreateItem(0)
With oEmail
.To = "[email protected]"
.CC = "[email protected]; [email protected]"
.Body = "Hi Team, this is a sample email"
.Display
Dim oOutlookInspect As OutLook.Inspector
Dim oWordDoc, oWordDoc1 As Word.Document
Dim oChartobj As ChartObject
For Each oChartobj In ActiveSheet.ChartObjects
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
Next
Set OutAppInspect = .GetInspector
Set oWordDoc1 = OutAppInspect.WordEditor
ActiveSheet.Range("StockData").Copy
Set oWordRng1 = oWordDoc1.Application.ActiveDocument.Content
oWordRng1.InsertAfter " " & vbNewLine
oWordRng1.Collapse Direction:=wbCollapseEnd
oWordRng1.Paste
End With
Set oEmail = Nothing
Set oOutlook = Nothing
End Sub
I want to try it and see what happens, and I need to solve this error code. I have to get new chart and pivot tables.
New contributor
Code is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.