Eem Jee
Eem Jee

Reputation: 1319

Checking the size of the attachments

So I have a column that is for attachments directory only. It starts from O24:O33 and its not all the time that all of the fields are filled out for attachments. I have this code that adds the directories in the outlook mail as attachments.

Dim objmail as Object
Dim attach as object
Dim i as integer, lrow as long

lRow = Cells(Rows.count, 15).End(xlUp).Row

Set objMail = objOutlook.CreateItem(0)
Set attach = objMail.attachments

For i = 23 To lRow
      attach.add main.Range("O" & i).Value
Next i

What I want now is to check the total size of the attachments and if it will be greater than 10mb, it will prompt the user that he has reached the maximum size of attachments. Any help? Thanks.

Upvotes: 0

Views: 707

Answers (2)

Slai
Slai

Reputation: 22906

You can get the size of a file in Bytes with FileLen

Dim totalSize As Long
For i = 23 To lRow
     totalSize = totalSize + FileLen( main.Cells(i, "O").Value2 )
Next i

Upvotes: 2

Dmitry Streblechenko
Dmitry Streblechenko

Reputation: 66356

Save the message first (MailItem.Save to make sure the size is updated), sum up the values of all Attachment.Size properties.

Upvotes: 2

Related Questions