Aschrum
09-17-2013, 01:04 AM
Hi folks,
I want to select some cells of a worksheet under specific conditions, do addition and paste it into an email.
My current issue is to paste the Excel content into the body.
What I've got in this regard is the following.
Dim xl As Object
Set xl = CreateObject("Excel.Application")
With xl
.Workbooks.Open ("C:\[...]\abc.xls")
.DisplayAlerts = False
.Visible = True
.Range("K16:K17").Select 'Test Range
.Selection.Copy
End With 'No issues till this point
With itm
.To = "a@b.c"
.Subject = "TEST"
.Body = "Guten Morgen," _
& vbCrLf & xl.Selection.Paste 'The mailitem works, the pasting doesn't
.Display
End With
Another snippet I've tried.
Dim xl As Object
Set xl = CreateObject("Excel.Application")
Dim rng As VariantDim cl As Variant
Dim ws As Variant 'As Worksheet not possible in Outlook?
With xl
.Workbooks.Open ("C:\[...]\abc.xls")
.DisplayAlerts = False
.Visible = True
Set ws = ActiveSheet
rng = .Range("K16:K17"). 'Select 'Test Range
'.Selection.Copy
'.Selection.Paste
With rng
.Parent.Select
Set cl = ActiveCell
.Select
ActiveWorkbook.EnvelopeVisible = True
With .Parent.MailEnvelope
.Introduction = "Hallo" 'This line doesn't take any effect
With itm
.To = "a@b.c"
.Subject = "TEST"
.Send
End With
End With
End With
End With
Thanks in advance for any suggestions.
André
I want to select some cells of a worksheet under specific conditions, do addition and paste it into an email.
My current issue is to paste the Excel content into the body.
What I've got in this regard is the following.
Dim xl As Object
Set xl = CreateObject("Excel.Application")
With xl
.Workbooks.Open ("C:\[...]\abc.xls")
.DisplayAlerts = False
.Visible = True
.Range("K16:K17").Select 'Test Range
.Selection.Copy
End With 'No issues till this point
With itm
.To = "a@b.c"
.Subject = "TEST"
.Body = "Guten Morgen," _
& vbCrLf & xl.Selection.Paste 'The mailitem works, the pasting doesn't
.Display
End With
Another snippet I've tried.
Dim xl As Object
Set xl = CreateObject("Excel.Application")
Dim rng As VariantDim cl As Variant
Dim ws As Variant 'As Worksheet not possible in Outlook?
With xl
.Workbooks.Open ("C:\[...]\abc.xls")
.DisplayAlerts = False
.Visible = True
Set ws = ActiveSheet
rng = .Range("K16:K17"). 'Select 'Test Range
'.Selection.Copy
'.Selection.Paste
With rng
.Parent.Select
Set cl = ActiveCell
.Select
ActiveWorkbook.EnvelopeVisible = True
With .Parent.MailEnvelope
.Introduction = "Hallo" 'This line doesn't take any effect
With itm
.To = "a@b.c"
.Subject = "TEST"
.Send
End With
End With
End With
End With
Thanks in advance for any suggestions.
André