Results 1 to 6 of 6
  1. #1
    5 Star Lounger
    Join Date
    Jul 2001
    Location
    Terneuzen, Netherlands
    Posts
    895
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Get Attachment sizes from email (Office 2003)

    I have the code below (condensed for clarity); I now need to get the size of each attachment.
    <pre>Set olApp = New Outlook.Application
    Dim nsp As Namespace
    Dim fld As MAPIFolder
    Dim itms As Items
    Dim i As Long, j As Long, k As Long, Mx As Long
    Row = 3
    Range("A4:Z8000").Clear
    Set nsp = olApp.GetNamespace("MAPI")
    Set fld = nsp.PickFolder
    Set itms = fld.Items
    Mx = itms.Count
    '
    For i = Mx To 1 Step -1
    With itms(i)
    If .Class = olMail Then
    Range("A1").Offset(Row, 0) = .Subject
    Range("A1").Offset(Row, 1) = .SenderName
    Range("A1").Offset(Row, 2) = .ReceivedTime
    Range("A1").Offset(Row, 3) = .Size
    j = .Attachments.Count
    Range("A1").Offset(Row, 4) = j
    If j > 0 Then
    For k = 1 To j
    Range("A1").Offset(Row, 5 + 3 * (k - 1)) = .Attachments.Item(k).Type
    If .Attachments.Item(k).Type = 1 Or .Attachments.Item(k).Type = 5 Then
    Range("A1").Offset(Row, 6 + 3 * (k - 1)) = .Attachments.Item(k).Filename
    Range("A1").Offset(Row, 7 + 3 * (k - 1)) = .Attachments.Item(k).Position
    End If
    Next
    End If
    Row = Row + 1
    End If
    End With
    Next
    '
    Set fld = Nothing
    Set nsp = Nothing
    </pre>


    Something that looks like .Attachments.Item(k).Size does not work regretfully... Suggestions?

    Also, I found this for the Type, and found out that only Type 1 and 5 are attached. Any clarification?

    '4 = olbyreference (is included)
    '1 = olbyvalue (file attachment)
    '5 = oleembedded item (file attachment)
    '6 = olole

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Get Attachment sizes from email (Office 2003)

    The size of an attachment is not exposed in Outlook VBA. You'll need to use CDO to get the PR_ATTACH_SIZE property, or Outlook Redemption (free for development purposes, not free for commercial use), which exposes lots of properties not available in Outlook VBA.

  3. #3
    5 Star Lounger
    Join Date
    Jul 2001
    Location
    Terneuzen, Netherlands
    Posts
    895
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Get Attachment sizes from email (Office 2003)

    OK, so how do I pick a folder like in the PickFolder call above and get the thing to start processing from there? I'm sorry but I need some kick-starting to get me going in this new world... ;-)

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Get Attachment sizes from email (Office 2003)

    I think you're on your own here - I have no experience with these libraries.
    There's an example on the Redemption site: RDO - Attachment but it might be too limited for you.

  5. #5
    5 Star Lounger
    Join Date
    Jul 2001
    Location
    Terneuzen, Netherlands
    Posts
    895
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Get Attachment sizes from email (Office 2003)

    Sorry, I quickly looked at the Redemption stuff but that's too much for me for now too.

    My question was not clear: I meant: how would I do this and get started with CDO?

    EJ

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Get Attachment sizes from email (Office 2003)

    There is lots of stuff on CDOLive - The Premier Resource for Microsoft Collaboration Data Objects, even though it hasn't been kept up-to-date. But it's all very technical. <img src=/S/sad.gif border=0 alt=sad width=15 height=15>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •