FSOFile Not Working

Eric Penfold

Active Member
Joined
Nov 19, 2021
Messages
431
Office Version
  1. 365
Platform
  1. Windows
  2. Mobile
Hi

Can`t understand why the FSOFile is not working it say`s wrong number of arguments error 450?

VBA Code:
Sub Send_Email(EmailTo As String, EmailCC As String, EmailBCC As String, EmailSubject As String, EmailBody As String, Optional EmailAttachement 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 EmailAttachement <> "" Then
            Source = EmailAttachement
            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



    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)
    Set FSOFile = FSOFolder.Files
    
    
    For Each FSOFile In FSOFolder.FSOFiles
        If (FSOFile.Name Like "*" & ".pdf" Or FSOFile.Name Like "*" & ".STEP" Or FSOFile.Name Like "*" & ".DXF") Then
            Call Send_Email("EmailTo", "Me.Email_List.Value", "Subject", "Me.Enter_Number.Value" & " " & Format(Date, "dd/mmmm/yyyy"), "EmailBody", "File")
        End If
    Next FSOFile
    
    
End Sub
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
Maybe this must be attachment not "attachement"

If EmailAttachement <> "" Then
Source = EmailAttachement
EmailItem.Attachments.Add Source
End If
 
Upvote 0
I have taken a look at your original post, and I noticed two problems.

First, you'll need to delete the following line...

VBA Code:
Set FSOFile = FSOFolder.Files

Then you'll need to replace...

VBA Code:
For Each FSOFile In FSOFolder.FSOFiles

with

VBA Code:
For Each FSOFile In FSOFolder.Files

Hope this helps!
 
Upvote 0
Solution

Forum statistics

Threads
1,223,884
Messages
6,175,177
Members
452,615
Latest member
bogeys2birdies

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