USFengBULLS
Board Regular
- Joined
- May 7, 2018
- Messages
- 66
- Office Version
- 365
- Platform
- Windows
Hello, I am working on a code to send multiple files in a listbox on a userform as attachments in outlook. I have this linked to a commandButton click event but I need further guidance on it.
there is a command button that first populates the list box with the multiple files the user selects. The problem I have it with the Email Command button Click, I think I am close.
Really I just want it to open Outlook and have the files that are in the listbox be as attachments and then the user will fill the rest from there.
Right now it is giving me a Runtime error 424, Object Required and highlights the "Attachments.Add (lbxEmail.Selected)" Line in the code.
Here is the code so far:
there is a command button that first populates the list box with the multiple files the user selects. The problem I have it with the Email Command button Click, I think I am close.
Really I just want it to open Outlook and have the files that are in the listbox be as attachments and then the user will fill the rest from there.
Right now it is giving me a Runtime error 424, Object Required and highlights the "Attachments.Add (lbxEmail.Selected)" Line in the code.
Here is the code so far:
VBA Code:
Private Sub cmdEmail_Click()
Dim oOutlook As Outlook.Application
Dim oEmailItem As MailItem
If oOutlook Is Nothing Then
Set oOutlook = New Outlook.Application
End If
Set oEmailItem = oOutlook.CreateItem(olMailItem)
With oEmailItem
.BodyFormat = olFormatHTML
.To = vbNullString
.CC = vbNullString
.Subject = vbNullString
For n = 0 To lbxEmail.ListCount - 1
Attachments.Add (lbxEmail.Selected(n))
Next n
.Display
End With
End Sub