Laxminarayan
New Member
I need to Copy Selected Excel Data to Outlook, i have created an VBA Code for the normal stuffs as Creating the body of the Email and auto Fills "To" and From data in Outlook,
Below is the VBA Code which i have used.
In Here in Sheets Drafter and Range J9 which has some data i need to copy paste the Entire data in Outlook, currently its not possible with the below Code,
Can anyone advise or amend the below code so that i can get the necessary results.
Let me know in case of any issues.
Below is the VBA Code which i have used.
In Here in Sheets Drafter and Range J9 which has some data i need to copy paste the Entire data in Outlook, currently its not possible with the below Code,
Can anyone advise or amend the below code so that i can get the necessary results.
Let me know in case of any issues.
Code:
Sub AutoCreateMail()
Application.ScreenUpdating = False
Selection.Copy
Sheets("Drafter").Visible = True
Sheets("Drafter").Select
Range("J9").Select
On Error GoTo Handler
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
On Error GoTo 0
Dim objOutlook As Object
Dim objMail As Object
Dim EmailFrom As Range
Dim EmailTo As Range
Dim EmailCc As Range
Dim EmailSubject As Range
Dim EmailBody1 As Range
Dim EmailBody2 As Range
Dim EmailBody3 As Range
Dim EmailBody4 As Range
Dim EmailBody5 As Range
Dim EmailBody6 As Range
Set objOutlook = CreateObject("Outlook.Application")
Set objMail = objOutlook.CreateItem(0)
With ActiveSheet
Set EmailFrom = .Range("B1")
Set EmailTo = .Range("B2")
Set EmailCc = .Range("B3")
Set EmailSubject = .Range("B4")
Set EmailBody1 = .Range("B5")
Set EmailBody2 = .Range("B6")
Set EmailBody3 = .Range("B7")
Set EmailBody4 = .Range("B8")
Set EmailBody5 = .Range("B9")
Set EmailBody6 = .Range("B10")
End With
With objMail
.Display
.SentOnBehalfOfName = EmailFrom.Value
.To = EmailTo.Value
.Cc = EmailCc.Value
.Subject = EmailSubject.Value
.HTMLBody = "<br>" & EmailBody1.Value & "<br><br>" & EmailBody2.Value & "<br><br>" & EmailBody3.Value & "<br><br><br>" & EmailBody4.Value & "<br><br><br>" & EmailBody5.Value & "<br><br><br>" & EmailBody6.Value & "<br>" & .HTMLBody
End With
ThisWorkbook.Activate
Sheets("Drafter").Select
Range("J:N").Select
Selection.ClearContents
Sheets("Drafter").Visible = False
Sheets("Planner").Select
Application.ScreenUpdating = True
Handler:
Sheets("Drafter").Visible = False
Application.CutCopyMode = False
Exit Sub
End Sub