Hi, I am trying to automate an email which can have more than ONE attachments in the MAIL. I am using CommonDialog control to Browse the Files to attach in mail, however the moment I attach more than ONE file it gives me Error "ONLY FILES CAN BE ATTACHMENTS C:yourpath/foldername is a FOLDER AND CANNOT BE ATTACHED"
Run Time Error - 2147352567 (80020009)
Here is the CODE I am using:- Can you please help with what is missing here? Thanks in advance...
Run Time Error - 2147352567 (80020009)
Here is the CODE I am using:- Can you please help with what is missing here? Thanks in advance...
HTML Code:
Private Sub Command5_Click()
CommonDialog1.Flags = cdlOFNAllowMultiselect + cdlOFNLongNames + cdlOFNExplorer
On Error GoTo MS ' Error control
Dim vFiles As Variant
Dim lFile As Long
With CommonDialog1
.FileName = "*" 'Clear the filename
.CancelError = False 'Gives an error if cancel is pressed
.DialogTitle = "Select File(s)..."
.Flags = cdlOFNAllowMultiselect Or cdlOFNExplorer Or cdlOFNHideReadOnly 'Falgs, allows Multi select, Explorer style and hide the Read only tag
.Filter = "All files (*.*)|*.*"
.ShowOpen
End With
MS:
Dim oOLook As Object
Dim oEmail As Outlook.MailItem
Const QUOTE = """"
'
Set oOLook = CreateObject("Outlook.Application")
oOLook.Session.Logon
Set oEmail = oOLook.CreateItem(0)
With oEmail
.To = "myemail@xyzmail.com"
.Subject:"I love" & QUOTE & "steve jobs"""
oEmail.attachments.Add (CommonDialog1.FileName)
.Send
End With
Set oEmail = Nothing
Set oOLook = Nothing
On Error GoTo 0
End Sub