Hi, I've put together the following by combining some help from people on here and code on other forms. It works great for getting charts, ranges, etc, to set up an Outlook email from excel using VBA. Only trouble I am having is changing formatting. Or specifically, putting new lines between the multiple pasted ranges/graphs. (and YES, I've tried: .Body = wEditor & vbNewLine & wEditor2 (and of course I added a wEditor2...paste in the right spot), but that doesnt work.
Here is the code, any suggestions are greatly appreciated.
Thanks!
Option Explicit
Sub CopyAndPasteToMailBody()
Dim mailApp, mail As Object
Dim olMailItem, wEditor As Variant
Dim vInspector As Variant
Dim vInspector2 As Variant
Dim wEditor2 As Variant
Dim rngTo As Range, rngCc As Range, rngSubject As Range
Set mailApp = CreateObject("Outlook.Application")
Set mail = mailApp.CreateItem(olMailItem)
mail.display
With Sheets("Summary")
Set rngTo = .Range("R8")
Set rngCc = .Range("R9")
Set rngSubject = .Range("C63")
End With
With mail
.To = rngTo.Value
.CC = rngCc.Value
.Subject = rngSubject.Value
.Body = wEditor
Set vInspector = mail.getInspector
Set wEditor = vInspector.WordEditor
ActiveSheet.Range("V7:Z7").Copy
wEditor.Application.Selection.Paste
ActiveSheet.Range("V9:Z58").Copy
wEditor.Application.Selection.Paste
ActiveSheet.ChartObjects("testchart").Activate
ActiveChart.ChartArea.Copy
wEditor.Application.Selection.Paste
End With
End Sub
Here is the code, any suggestions are greatly appreciated.
Thanks!
Option Explicit
Sub CopyAndPasteToMailBody()
Dim mailApp, mail As Object
Dim olMailItem, wEditor As Variant
Dim vInspector As Variant
Dim vInspector2 As Variant
Dim wEditor2 As Variant
Dim rngTo As Range, rngCc As Range, rngSubject As Range
Set mailApp = CreateObject("Outlook.Application")
Set mail = mailApp.CreateItem(olMailItem)
mail.display
With Sheets("Summary")
Set rngTo = .Range("R8")
Set rngCc = .Range("R9")
Set rngSubject = .Range("C63")
End With
With mail
.To = rngTo.Value
.CC = rngCc.Value
.Subject = rngSubject.Value
.Body = wEditor
Set vInspector = mail.getInspector
Set wEditor = vInspector.WordEditor
ActiveSheet.Range("V7:Z7").Copy
wEditor.Application.Selection.Paste
ActiveSheet.Range("V9:Z58").Copy
wEditor.Application.Selection.Paste
ActiveSheet.ChartObjects("testchart").Activate
ActiveChart.ChartArea.Copy
wEditor.Application.Selection.Paste
End With
End Sub