none
VBA Sent Date RRS feed

  • Question

  • Hello,

    Here is a part of macro. What should I do to download a Sent date of message(which I got) from Outlook? 

    Set aplikacja = CreateObject("Outlook.Application")
        Set skrzynka = aplikacja.GetNamespace("MAPI")
        Set folder = skrzynka.GetDefaultFolder(6)
        For Each wiadomosc In folder.Items

    'Here I am in the message in the inbox.

            a = wiadomosc.Sender.Address
            b = 'Sent date
        Next wiadomosc

    Thank You for any help.

    Wednesday, February 12, 2014 3:58 PM

Answers

All replies

  • Use the MailItem.SentOn property.


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    • Marked as answer by d100s20 Wednesday, February 12, 2014 4:18 PM
    • Unmarked as answer by d100s20 Wednesday, February 12, 2014 4:18 PM
    • Marked as answer by Luna Zhang - MSFTModerator Tuesday, February 18, 2014 9:44 AM
    Wednesday, February 12, 2014 4:15 PM
  • I tried to write:
    b = wiadomosc.SendOn and b = wiadomosc.MailItem.SendOn. It doesn't work.
    • Edited by d100s20 Wednesday, February 12, 2014 4:22 PM
    Wednesday, February 12, 2014 4:19 PM
  • "It doesn't work" as in you get an exception? What is it? Or you get an unexpected value?

    In the former case, are you sure you are dealing with a MailItem object and not a report item or a meeting request?


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Wednesday, February 12, 2014 4:24 PM
  • No, I am not. 
    Maybe I will show all macro:
    Sub odbierz()
        'deklaracja zmiennych
        Dim aplikacja, skrzynka, folder, zalacznik, wiadomosc As Object
        Dim nazwa As String
        'instrukcje
        Set aplikacja = CreateObject("Outlook.Application")
        Set skrzynka = aplikacja.GetNamespace("MAPI")
        Set folder = skrzynka.GetDefaultFolder(6)
        For Each wiadomosc In folder.Items
            a = wiadomosc.Sender.Address 'przetrzymuje adresata
            b = wiadomosc.MailItem.SendOn
            For Each zalacznik In wiadomosc.Attachments
                nazwa = zalacznik.Filename
                If nazwa = "krr.xlsm" Then
                    sciezka = "C:\InfoSklepy\" & zalacznik.Filename
                    zalacznik.SaveAsFile sciezka
                    Exit Sub
                End If
            Next zalacznik
        Next wiadomosc
    End Sub

    On a variable "b" I have a statement: "Object doesn't support this property or method".
    I think that I do something bad...


    • Edited by d100s20 Wednesday, February 12, 2014 4:36 PM
    Wednesday, February 12, 2014 4:36 PM
  • You need to check the item type:

    For Each wiadomosc In folder.Items
      if wiadomosc.Class = 43 Then 'olMail
         ...
      End If 
    Next
    


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!


    Wednesday, February 12, 2014 4:40 PM