CarlosTJackal
New Member
- Joined
- Mar 14, 2018
- Messages
- 1
Hi,
I am very new to VBA Code and am struggling to achieve adding an Excel 2010 workbook (or even Active Worksheet) to an e-mail using VBA and wondered if anyone could help?
So I've created a form in Excel 2010 which I want colleagues to complete. When they've done that, I'd like them to be able to press a button in Excel which then creates an e-mail and attaches the Active Sheet (or the entire workbook).
I don't want the e-mail to be sent automatically, as I would like people to be able to amend the e-mail text themselves. At the moment, I've managed to have Excel create the mail (with some basic text in it) and prefill the e-mail address I want it to be sent to but I can't work out (or find online) how to get the worksheet (or workbook) attached.
My code for creating the e-mail (as above) is here:
Private Sub CommandButton21_Click()
Dim xOutApp As Object
Dim xOutMail As Object
Dim xMailBody As String
On Error Resume Next
Set xOutApp = CreateObject("Outlook.Application")
Set xOutMail = xOutApp.CreateItem(0)
xMailBody = "Hi," & vbNewLine & vbNewLine & _
"Please process the attached Leaver." & vbNewLine & vbNewLine & _
"Thanks"
On Error Resume Next
With xOutMail
.To = "GILiveSystemSupport@lloydsbanking.com"
.CC = ""
.BCC = ""
.Subject = "LEAVER'S FORM - "
.Body = xMailBody
.Display 'or use .Send
End With
On Error GoTo 0
Set xOutMail = Nothing
Set xOutApp = Nothing
End Sub
Can anyone help with the last part as it's driving me nuts!!
Thanks in advance
I am very new to VBA Code and am struggling to achieve adding an Excel 2010 workbook (or even Active Worksheet) to an e-mail using VBA and wondered if anyone could help?
So I've created a form in Excel 2010 which I want colleagues to complete. When they've done that, I'd like them to be able to press a button in Excel which then creates an e-mail and attaches the Active Sheet (or the entire workbook).
I don't want the e-mail to be sent automatically, as I would like people to be able to amend the e-mail text themselves. At the moment, I've managed to have Excel create the mail (with some basic text in it) and prefill the e-mail address I want it to be sent to but I can't work out (or find online) how to get the worksheet (or workbook) attached.
My code for creating the e-mail (as above) is here:
Private Sub CommandButton21_Click()
Dim xOutApp As Object
Dim xOutMail As Object
Dim xMailBody As String
On Error Resume Next
Set xOutApp = CreateObject("Outlook.Application")
Set xOutMail = xOutApp.CreateItem(0)
xMailBody = "Hi," & vbNewLine & vbNewLine & _
"Please process the attached Leaver." & vbNewLine & vbNewLine & _
"Thanks"
On Error Resume Next
With xOutMail
.To = "GILiveSystemSupport@lloydsbanking.com"
.CC = ""
.BCC = ""
.Subject = "LEAVER'S FORM - "
.Body = xMailBody
.Display 'or use .Send
End With
On Error GoTo 0
Set xOutMail = Nothing
Set xOutApp = Nothing
End Sub
Can anyone help with the last part as it's driving me nuts!!
Thanks in advance