1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
| Public Sub Add_Attachment()
Dim FileSize As Double, FilePath As String, objTheFile As Object, objFileSystem As Object, J As Integer, FileName As String
Dim blnSlash As Boolean, FileType As String
FileName = "C:\chemin\video.mp4"
Set objFileSystem = CreateObject("Scripting.FileSystemObject")
On Error Resume Next
Err.Clear
Set objTheFile = objFileSystem.getfile(FileName)
If Err.Number = 53 Then 'File not found then
Err.Source = "Email Engine Add_Attachment"
MsgBox prompt:="Error number " & Err.Number & vbCrLf & "Source: " & Err.Source & vbCrLf & vbCrLf & Err.Description & vbCrLf & FileName, Buttons:=vbCritical, Title:="Email Engine Error"
Err.Clear
Set objFileSystem = Nothing
Set objTheFile = Nothing
Exit Sub
ElseIf Err.Number > 0 Then
Err.Raise Number:=Err.Number, Source:=Err.Source, Description:=Err.Description, HelpFile:=Err.HelpFile, HelpContext:=Err.HelpContext
ElseIf objTheFile Is Nothing Then
Err.Number = 91
Err.Description = "Object Variable Not Set"
Err.Source = "Email Engine Add_Attachment"
MsgBox prompt:="Error number " & Err.Number & vbCrLf & "Source: " & Err.Source & vbCrLf & vbCrLf & "Unable to open file: " & Err.Description & vbCrLf & FileName, Buttons:=vbCritical, Title:="Email Engine Error"
Err.Clear
Set objFileSystem = Nothing
Set objTheFile = Nothing
Exit Sub
End If
On Error GoTo 0
FileSize = objTheFile.Size
FilePath = objTheFile.Path
'get the size of the file
FileSize = Application.WorksheetFunction.Round(FileSize / 1048576, 2) 'Size in MB
Debug.Print (FileSize)
Set objFileSystem = Nothing
Set objTheFile = Nothing
End Sub |