Struggling with Email Attachments Code

Eric Penfold

Active Member
Joined
Nov 19, 2021
Messages
424
Office Version
  1. 365
Platform
  1. Windows
  2. Mobile
With this code the last part of Send Email FSOFile says "FSOFile" rather than the path and name of file??

VBA Code:
For Each FSOFile In FSOFolder.Files
        If (FSOFile.Name Like "*" & ".pdf" Or FSOFile.Name Like "*" & ".STEP" Or FSOFile.Name Like "*" & ".DXF") Then
            Call Send_Email("Me.Email_List.Value", "", "", "Me.Enter_Number.Value" & " " & Format(Date, "dd/mmmm/yyyy"), _
            "Process Frost Drawings", "FSOFile")
        End If
    Next FSOFile

Main Code below

VBA Code:
Sub Send_Email(EmailTo As String, EmailCC As String, EmailBCC As String, EmailSubject As String, EmailBody As String, EmailAttachment As String)
    Dim EmailApp As Object
    Dim EmailItem As Object
    Dim Source As String

    Set EmailApp = CreateObject("Outlook.Application")
    Set EmailItem = EmailApp.CreateItem(0)
    
    With EmailItem
        .to = EmailTo
        .CC = EmailCC
        .BCC = EmailBCC
        .Subject = EmailSubject
        .Body = EmailBody
        
        If EmailAttachment <> "" Then
            .Source = EmailAttachment
            EmailItem.Attachments.Add Source
        End If
        
        .Display
        'EmailItem.Send
    End With
End Sub
Private Sub Email_Drawings_Click()

    Dim EmailApp As Object
    Dim EmailItem As Object
    Dim Source As String
    Dim FSOLibary As FileSystemObject
    Dim FSOFolder As Object
    Dim FSOFile As Object
    Dim strFolderCriteria As String, FolderName As String, strPath As String, strEmailTo As String
    Dim FilesToSend As String


    Set EmailApp = CreateObject("Outlook.Application")
    Set EmailItem = EmailApp.CreateItem(0)
    strFolderCriteria = (Me.Enter_Number.Value)
    strPath = "\\DF-AZ-FILE01\Company\R&D\Drawing Nos\Frost Grates"
    FolderName = strPath & "\" & strFolderCriteria & "\"
    Set FSOLibary = New Scripting.FileSystemObject
    Set FSOFolder = FSOLibary.GetFolder(FolderName)
    
    For Each FSOFile In FSOFolder.Files
        If (FSOFile.Name Like "*" & ".pdf" Or FSOFile.Name Like "*" & ".STEP" Or FSOFile.Name Like "*" & ".DXF") Then
            Call Send_Email("Me.Email_List.Value", "", "", "Me.Enter_Number.Value" & " " & Format(Date, "dd/mmmm/yyyy"), _
            "Process Frost Drawings", "FSOFile")
        End If
    Next FSOFile




End Sub
 
If i take away quotes then it shows an error "Runtime error 94" but if i leave them in it shows "Me.Email_List.Value"
 
Upvote 0

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
where are you pulling the email address's from

in the main routine what does Me.Email_List hold?
 
Upvote 0
The problem is with your refrence to the list box selection

Try searching for vba list box selection
 
Upvote 0
Solution

Forum statistics

Threads
1,215,336
Messages
6,124,331
Members
449,155
Latest member
ravioli44

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top