Patriot2879
Well-known Member
- Joined
- Feb 1, 2018
- Messages
- 1,259
- Office Version
- 2010
- Platform
- Windows
Hi, i hope you can help again beginner at this and still learning , i havethe code below which i have put in for command button, so when clicked it copiein the cells from a - k and only data that hasi want to do this multiple times heading above the code, but the below isnt helping any chanyou can help please?
Private Sub CommandButton7_Click()
Dim xOutApp As Object
Dim xOutMail As Object
Dim xMailBody As String
Dim objdata As DataObject
On Error Resume Next
Set xOutApp = CreateObject("Outlook.Application")
Set xOutMail = xOutApp.CreateItem(0)
Set objdata = New DataObject
.HTMLBody = "Replans," & "<br>" & .HTMLBody
ThisWorkbook.Sheets("Sheet2").Range("A:K").Copy
.HTMLBody = "ECOs," & "<br>" & .HTMLBody
ThisWorkbook.Sheets("Sheet3").Range("A:K").Copy
.HTMLBody = "Other Info," & "<br>" & .HTMLBody
ThisWorkbook.Sheets("Sheet4").Range("A:K").Copy
objdata.GetFromClipboard
varBody = objdata.GetText
With xOutMail
.To = "test@eonenergy.com"
.CC = "jeopardy.managers@eonenergy.com"
.BCC = ""
.Subject = "HANDOVER "
.body = varBody & vbCrLf & "Many thanks" & vbCrLf
.Display
.HTMLBody = "Hello There," & "<br>" & .HTMLBody
End With
On Error GoTo 0
Set xOutMail = Nothing
Set xOutApp = Nothing
End Sub
Code:
Dim xOutApp As Object
Dim xOutMail As Object
Dim xMailBody As String
Dim objdata As DataObject
On Error Resume Next
Set xOutApp = CreateObject("Outlook.Application")
Set xOutMail = xOutApp.CreateItem(0)
Set objdata = New DataObject
.HTMLBody = "Replans," & "<br>" & .HTMLBody
ThisWorkbook.Sheets("Sheet2").Range("A:K").Copy
.HTMLBody = "ECOs," & "<br>" & .HTMLBody
ThisWorkbook.Sheets("Sheet3").Range("A:K").Copy
.HTMLBody = "Other Info," & "<br>" & .HTMLBody
ThisWorkbook.Sheets("Sheet4").Range("A:K").Copy
objdata.GetFromClipboard
varBody = objdata.GetText
With xOutMail
.To = "test@eonenergy.com"
.CC = "jeopardy.managers@eonenergy.com"
.BCC = ""
.Subject = "HANDOVER "
.body = varBody & vbCrLf & "Many thanks" & vbCrLf
.Display
.HTMLBody = "Hello There," & "<br>" & .HTMLBody
End With
On Error GoTo 0
Set xOutMail = Nothing
Set xOutApp = Nothing
End Sub