Eric Penfold
Active Member
- Joined
- Nov 19, 2021
- Messages
- 431
- Office Version
- 365
- Platform
- Windows
- Mobile
Hi
Can`t understand why the FSOFile is not working it say`s wrong number of arguments error 450?
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