vba - Fetch all mails from inbox with pr_last_verb_executed into Excel sheet -
i want fetch outlook inbox emails excel sheet additional columns having data this mail replied on or this mail forwarded to
here code have done far
dim folder outlook.mapifolder dim irow integer mailboxname = 'mailbox name goes here pst_folder_name = "inbox" set folder = outlook.session.pickfolder 'folders(mailboxname).folders(pst_folder_name) if folder = "" msgbox "invalid data in input" goto end_lbl1: end if folder.items.sort "[receivedtime]", false limitdatetimevalue = 'date limit cellno = 2 irow = 1 folder.items.count on error resume next if folder.items.item(irow).receivedtime > limitdatetimevalue 'cellno = 2 on error resume next thisworkbook.sheets("inbox").range("a2").select fullsubjectline = folder.items.item(irow).subject if instr(1, fullsubjectline, "fe:", vbtextcompare) > 0 or instr(1, fullsubjectline, "fw:", vbtextcompare) > 0 or instr(1, fullsubjectline, "re:", vbtextcompare) filteredsubjectline = mid(fullsubjectline, 5) thisworkbook.sheets("inbox").cells(cellno, 2) = filteredsubjectline else thisworkbook.sheets("inbox").cells(cellno, 2) = folder.items.item(irow).subject end if thisworkbook.sheets("inbox").cells(cellno, 4) = left(folder.items.item(irow).body, 1024) if folder.items.item(irow).unread thisworkbook.sheets("inbox").cells(cellno, 6) = "unread" else thisworkbook.sheets("inbox").cells(cellno, 6) = "read" end if thisworkbook.sheets("inbox").cells(cellno, 1) = folder.items.item(irow).sendername thisworkbook.sheets("inbox").cells(cellno, 3) = folder.items.item(irow).receivedtime cellno = cellno + 1 end if next irow
the code extremely inefficient, multiple dot notation taken extreme. cache items collection before entering loop , retrieve item once on each iteration - otherwise oom have return brand new com object each ".".
on error resume next set vitems = folder.items irow = 1 vitems.count set vitem = vitems.item(irow) fullsubjectline = vitem.subject lastverbexecuted = vitem.propertyaccessor.getproperty("http://schemas.microsoft.com/mapi/proptag/0x10810003") if err.number <> 0 lastverbexecuted = 0 err.clear end if ... next
Comments
Post a Comment