Excel vba to extract outlook email --run error 438 -


please refer code below. code in excel vba , run in order extract large amount of email in outlook.

i have 3 questions , need help

  1. let's "inbox" has around 400+ emails , while running following code, error 438 came out when code searching 23 email. how can solve out?

  2. please refer code below:

    dim olmail variant 

    should use "object" or "variant"? better , why?

  3. in near future, outlook have more 1 email account. let's first email account abc@def.com , second email account abcd1@abc.com. in future, need run code first email account , second email account.

    how can switch them?

this current code:

sub getfrominbox()        dim olapp outlook.application        dim olns namespace        dim fldr mapifolder        dim olmail variant        dim i, ij integer        dim tt date        set olapp = new outlook.application        set olns = olapp.getnamespace("mapi")   '<questions 2---how can change in here add more 1 email address????? >         set fldr = olns.getdefaultfolder(olfolderinbox)            = 1           ij = 0         x = date         each olmail in fldr.items         ij = ij + 1            'if isnumeric((format(olmail.receivedtime, "dd/mm/yy")))            sheets("test").range("a1").select           sheets("test").range("i1").clear           sheets("test").range("i2") = ij  'question 1 : while ij counting 23, error 438 stopped in here?? have no idea why !! --->  sheets("test").range("i1").value = (format(olmail.receivedtime, "dd/mm/yy"))                   sheets("test").range("i1").numberformat = "dd/mm/yy"             tt = sheets("test").range("i1")           ' msgbox ("y-tt=" & tt & " receivedtime=" & olmail.receivedtime)             'else           'tt = 0            'msgbox ("n-tt=" & tt & " receivedtime=" & olmail.receivedtime)            'end if            ' tt = cdate(format(olmail.receivedtime, "dd/mm/yy"))      if tt >= range("h1")          'if instr(olmail.subject, "others") > 0 , tt >= range("h1")         if instr(olmail.subject, "others") > 0              activesheet.range("h2") = "y"             activesheet.cells(i, 1).value = olmail.subject             activesheet.cells(i, 2).value = olmail.receivedtime             activesheet.cells(i, 3).value = olmail.sendername              tt = cdate(format(olmail.receivedtime, "dd/mm/yy"))              activesheet.cells(i, 4).value = cdate(format(olmail.receivedtime, "dd/mm/yy"))                                          ' tt = activesheet.cells(i, 4).value              activesheet.cells(i, 5).value = (format(olmail.receivedtime, "hh:mm"))               msgbox ("tt=" & tt)               = + 1         end if       else      sheets("test").range("h2") = "n"       end if     next olmail      set fldr = nothing     set olns = nothing     set olapp = nothing      'tt = ""     end sub 

runtime error: 438 object not support property or method

the cause olmail.receivedtime olmail not object supports receivedtime.

if olmail.class = olmail     sheets("test").range("i1").value = (format(olmail.receivedtime, "dd/mm/yy")) end if 

this equivalent to:

if typename(olmail) = "mailitem"     sheets("test").range("i1").value = (format(olmail.receivedtime, "dd/mm/yy")) end if 

Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -