Email Download

Status
Not open for further replies.

parth007

New Member
Outlook version
Outlook 2010 64 bit
Email Account
Exchange Server
HI,

Need a VBA code which will help me doing below..

1) Download Microsoft Outlook Inbox data to Excel Sheet1 with date range
2) Download Microsoft Outlook SentItem data to Excel Sheet2 with date range

Now Highlight Sheet1 data which are not responded in Sheet2 .

Means those email which are not yest responded & doesnot exist in Sentitems should be highlighted..

Please suggest
 

parth007

New Member
Outlook version
Outlook 2010 64 bit
Email Account
Exchange Server
:(:(:(I am trying to build a code.. somehow got a wayout to download inbox & sentitems .. but it downloads entire inbox & sentitems.. i am not able to download via daterange.. more over how should i highlight those email which are not yest responded & doesnot exist in Sentitems

Code:
Sub ExportToExcelV2()
  Dim appExcel As Excel.Application
  Dim appOutlook As Outlook.Application
  Dim wkb As Excel.Workbook
  Dim wks As Excel.Worksheet
  Dim rng As Excel.Range
  Dim strSheet As String
  Dim strPath As String
  Dim intRowCounter As Integer
  Dim intColumnCounter As Integer
  Dim msg As Outlook.MailItem
  Dim nms As Outlook.Namespace
  Dim FolderSelected As Outlook.MAPIFolder
  Dim varSender As String
  Dim itm As Object
  Dim lngColIndex As Long
 
  On Error GoTo ErrHandler
  Set appExcel = Application 'CreateObject("Excel.Application")
  Set appOutlook = GetObject(, "Outlook.Application")
  appExcel.Application.Visible = True
  Set wkb = ThisWorkbook
  Set wks = wkb.Sheets(1)
  appExcel.GoTo wks.Cells(1)
  Set nms = appOutlook.GetNamespace("MAPI")
  Do
  'Stop
  Set FolderSelected = nms.PickFolder
  'Handle potential errors with Select Folder dialog box.
  If FolderSelected Is Nothing Then
  MsgBox "There are no mail messages to export", vbOKOnly, "Error"
  GoTo JumpExit
  ElseIf FolderSelected.DefaultItemType <> olMailItem Then
  MsgBox "These are not Mail Items", vbOKOnly, "Error"
  GoTo JumpExit
  ElseIf FolderSelected.Items.Count = 0 Then
  MsgBox "There are no mail messages to export", vbOKOnly, "Error"
  GoTo JumpExit
  End If
  'Copy field items in mail folder.
  intRowCounter = 1
  lngColIndex = 1
  wks.Cells(intRowCounter, lngColIndex).Resize(, 9).Value = Array("To", "From", "Subject", "Body", "Received", "Folder", "Category", "Flag Status", "Client")
  intRowCounter = wks.Cells(wks.Rows.Count, 1).End(xlUp).Row
  For Each itm In FolderSelected.Items
  intColumnCounter = 1
  If TypeOf itm Is MailItem Then
  Set msg = itm
  intRowCounter = intRowCounter + 1: Set rng = wks.Cells(intRowCounter, intColumnCounter): rng.Value = msg.To
  '============================================================
  varSender = ResolveDisplayNameToSMTP(msg.SenderEmailAddress, appOutlook)
  If varSender = vbNullString Then varSender = msg.SenderEmailAddress
  '============================================================
  wks.Cells(intRowCounter, 2).Resize(, 8).Value = Array(varSender, RemoveREFW(msg.Subject), Left(msg.Body, 50), msg.ReceivedTime, FolderSelected.Name, msg.Categories, msg.FlagStatus, "=ISNA(MATCH(RC[-7],NonClient,0))")
  varSender = vbNullString
  End If 'TypeOf
  Next itm
  Loop
JumpExit:
  Set appExcel = Nothing
  Set wkb = Nothing
  Set wks = Nothing
  Set rng = Nothing
  Set msg = Nothing
  Set nms = Nothing
  Set FolderSelected = Nothing
  Set itm = Nothing
  Exit Sub
ErrHandler:
  If Err.Number = 1004 Then
  MsgBox strSheet & " doesn't exist", vbOKOnly, "Error"
  Else
  MsgBox Err.Number & "; Description: " & Err.Description & vbCrLf & msg.ReceivedTime & vbCrLf & msg.Subject, vbOKOnly, "Error"
  End If
  Err.Clear: On Error GoTo 0: On Error GoTo -1
  GoTo JumpExit
 
End Sub
Function ResolveDisplayNameToSMTP(sFromName, objApp As Object)
 
  Dim oRecip As Recipient
  Dim oEU As ExchangeUser
  Dim oEDL As ExchangeDistributionList
 
  Set oRecip = objApp.Session.CreateRecipient(sFromName)
  oRecip.Resolve
  If oRecip.Resolved Then
  Select Case oRecip.AddressEntry.AddressEntryUserType
  Case OlAddressEntryUserType.olExchangeUserAddressEntry, OlAddressEntryUserType.olOutlookContactAddressEntry
  Set oEU = oRecip.AddressEntry.GetExchangeUser
  If Not (oEU Is Nothing) Then
  ResolveDisplayNameToSMTP = oEU.PrimarySmtpAddress
  End If
  Case OlAddressEntryUserType.olExchangeDistributionListAddressEntry
  Set oEDL = oRecip.AddressEntry.GetExchangeDistributionList
  If Not (oEDL Is Nothing) Then
  ResolveDisplayNameToSMTP = oEDL.PrimarySmtpAddress
  End If
  End Select
  End If
 
End Function
Private Function RemoveREFW(str As String) As String
  If Left$(UCase(str), 3) = "RE:" Or Left$(UCase(str), 3) = "FW:" Then
  str = Trim$(Mid$(str, 4))
  ElseIf Left(UCase(str), 4) = "FWD:" Then
  str = Trim$(Mid$(str, 5))
  End If
  RemoveREFW = Trim$(Replace$(Replace$(Replace$(str, "RE:", "", , , vbTextCompare), "FW:", "", , , vbTextCompare), "FWD:", "", , , vbTextCompare))
 
End Function
 

Michael Bauer

Senior Member
Outlook version
Outlook 2010 32 bit
Email Account
Exchange Server
The first part is easy. See the Restrict function, which is explained in the VBA help file, for the date range. It returns an Items collection, loop through that one instead of looping through FolderSelected.Items.
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
Now Highlight Sheet1 data which are not responded in Sheet2 .

Means those email which are not yest responded & doesnot exist in Sentitems should be highlighted..

Are you just going by email subjects? (That isn't very accurate). Better would be to use the last_verb so you can see if it was replied to on sheet 1.

The macro at http://www.slipstick.com/developer/code-samples/forward-messages-not-replied/ has an example using the last_verb. In your case, I would write the propertyaccessor value to the spreadsheet column.

This will add the reply or reply to all time to a string which you can write to a column in Excel. (As written, it ignores Forward.)
If propertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x10810003") = 102 or propertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x10810003") = 103 then
strReplytime = propertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x10820040")
 

parth007

New Member
Outlook version
Outlook 2010 64 bit
Email Account
Exchange Server
:)Hi Diane Thanks for the solution , will surely work on this...

I am succesful in bifurcating the emails
Sheet1 have inbox as per date range & sheet 2 have Sentitem as per date range..
I am stuck in below query..

Need a code which can highlight sheet1 row which is absent in sheet2 based on 3 conditions
Sheet1.Column B = Sheet2.A
and
Sheet1.Column C = Sheet2.C
and
Sheet1.Column E <= Sheet2.E
trying hard on it... but not getting anything right...
Please find attached sample sheet ... Please help/suggest
 

parth007

New Member
Outlook version
Outlook 2010 64 bit
Email Account
Exchange Server
I am not allowed to upload a sample sheet... please help suggest
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
You'll need to zip it until i can figure out how to add more file types but I don't need to see the sheet.

Vlookup should work.


for example, enter =VLOOKUP(A1,Sheet2!$A:A,1,0) into Sheet1 - cell B1 and fill down. The formula compares Sheet1 A1 to the table in Sheet2 column A. If the value in A1 doesn't appear in Sheet2 column A the formula will result in #n/a. If the subjects you are comparing are in different columns, change the columns accordingly.
 

parth007

New Member
Outlook version
Outlook 2010 64 bit
Email Account
Exchange Server
Hi Diane,

Please find the attached Zip file ..
Searching a code which can highlight sheet1 row which is absent in sheet2 based on 3 conditions
Sheet1.Column B = Sheet2.A
and
Sheet1.Column C = Sheet2.C
and
Sheet1.Column E <= Sheet2.E
 

Attachments

  • Sample.zip
    8.5 KB · Views: 326

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
You need to use Vlookup and then conditional formatting to mark the cells.
Put these in row one and pull down to fill (the B1, C1, E1 values will update)
=VLOOKUP(B1,Sheet2!$A:A,1,0)

=VLOOKUP(C1,Sheet2!$C:C,1,0)

=VLOOKUP(E1,Sheet2!$E:E,1,0)

Then set up conditional formatting rules or use another column to compare =if(b1 = j1, "", "no match") where j1 = the column the first vlookup is in. Repeat for the other 2. You could make a complicated if formula that checks all 3 at once
something like this:
= if(b1=j1,if(c1=k1, if(e1=l1,"", "no match"),"no match"), "no match")

then sort on that column or use conditional formatting to highlight.
 

parth007

New Member
Outlook version
Outlook 2010 64 bit
Email Account
Exchange Server
Hi Diane,

I am not able to use the above one on excel. if you can look into the sheet attached that will be helpful..
Moreover instead of this.. is their any VBA code which will highlight the email rows in inbox which is not yet responded & absent in sentitem email sheet?
Please suggest
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
Trying to do a lookup between and excel sheet and the inbox would be difficult. It would be much easier to use the last_verb propertyaccessor method and get the replied to state (and the time of the reply) from the message properties as you create the spreadsheet.

If you just need to look at the messages in Outlook, you can add the last verb column to outlook. Use conditional formatting to highlight the messages in Outlook.
http://www.slipstick.com/exchange/adding-extended-mapi-fields-to-outlook/

The macro in the link I posted earlier can be tweaked to set a category on messages not replied to.
http://www.slipstick.com/developer/code-samples/forward-messages-not-replied/ - use objVariant.Categories = "Needs Reply" instead of the forward stuff.
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
BTW, i was able to get the lookups working but there are definitely issues. It's having problems with the subject field (always returns false) and the sort order of the first column affects it.
2015-02-18_9-52-53.png
 

parth007

New Member
Outlook version
Outlook 2010 64 bit
Email Account
Exchange Server
:)Hi Diane, cool, will try this one.. thanks for all help...
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
G Download pdf attachments only if email subject has one of words Outlook VBA and Custom Forms 8
B Automatic picture download and changing email addresses Using Outlook 3
rezazy Do not download old email Using Outlook 1
A Links in email getting error message about group policy Using Outlook 4
richardwing Auto forward email that is moves into a specific outlook folder Outlook VBA and Custom Forms 2
J Recommendations for Outlook Duplicate Email Remover Using Outlook 6
Geldner Tweak Junk Email Reporting tool to default to particular email on send? Using Outlook 3
S Outlook 365 Can I change the possible range of highlighting colours when writing an Outlook email? Using Outlook 1
V Can one change the formatting of email title blocks? Using Outlook 0
P default font when sending email from browser Using Outlook 1
D VBA Macro to Print and Save email to network location Outlook VBA and Custom Forms 1
B IMAP server rejects sent email - cannot deliver messages Using Outlook 2
TedSch Small vba to kill political email Outlook VBA and Custom Forms 3
X Open Hyperlinks in an Outlook Email Message (Help with Diane's solution) Outlook VBA and Custom Forms 3
e_a_g_l_e_p_i Email notifications changed with Outlook 2021 Using Outlook 8
glnz How to retrieve or redo Verizon.net email password without affecting Outlook connection? Using Outlook 1
Z Copy specific email body text Outlook VBA and Custom Forms 0
D ISOmacro to extract active mail senders name and email, CC, Subject line, and filename of attachments and import them into premade excel spread sheet Outlook VBA and Custom Forms 2
M Outlook 365 refuses to send email Using Outlook 1
B Search and Find Email by Folder Name Outlook VBA and Custom Forms 2
K Closing external IMAP email... Outlook 2013 Using Outlook 0
L Capture email addresses and create a comma separated list Outlook VBA and Custom Forms 5
C Email bomb processing Outlook VBA and Custom Forms 1
O What would be the recommended way to change an email address (family member)? Using Outlook 0
A Outlook 2016 Macro to Reply, ReplyAll, or Forward(but with composing new email) Outlook VBA and Custom Forms 0
L Checking Sender Email Address for trusted domain from list on intranet Outlook VBA and Custom Forms 4
J How do you disable address search box when typing @ in body of email? Using Outlook 0
S HTML Code Embedded in String Within Open Outlook Email Preventing Replace(Application.ActiveInspector.CurrentItem.HTMLBody From Working Outlook VBA and Custom Forms 4
Victor.Ayala Automated way to check the option "Show this folder as an email Address Book" Outlook VBA and Custom Forms 2
D Wrong email address in Outlook 2003 "From" tab in new outgoing emails Using Outlook 4
D Forwarding email based on the attachment file type and specific text found on the attachment file name Outlook VBA and Custom Forms 1
F Forward incoming email with 4 embedded images in the body without original sender Outlook VBA and Custom Forms 22
W Macro to Filter Based on Latest Email Outlook VBA and Custom Forms 6
D Create advanced search (email) via VBA with LONG QUERY (>1024 char) Outlook VBA and Custom Forms 2
C Outlook 2007 Removing then adding account restores junk email processing Using Outlook 0
G Place jpg in body of email Outlook VBA and Custom Forms 1
F Wishlist Outlook suddenly began synchronizing deleted items every time I delete a single email. Using Outlook 2
N Save Selected Email Message as .msg File Outlook VBA and Custom Forms 12
HarvMan Toggle between calendar and email in Outlook 365 Using Outlook 12
F Email being marked as Spam by Gmail and not being visible in Outlook Using Outlook 5
G Email time stamp Using Outlook 2
G Schedule recurring email and attachments display Outlook VBA and Custom Forms 3
G Save and Rename Outlook Email Attachments Outlook VBA and Custom Forms 0
B Need to Copy an email to a subfolder Outlook VBA and Custom Forms 2
M How to setup outlook after importing old account information - Entering email account info creates with "(1)" after the account! Using Outlook 1
K Multiple Rules on Single Email Using Outlook 2
F VBA to move email from Non Default folder to Sub folders as per details given in excel file Outlook VBA and Custom Forms 11
e_a_g_l_e_p_i Outlook 2010 How to set default email address for website links Using Outlook 3
O Same email address, same person, names in so many ways Using Outlook 4
D Create new email from the received Email Body with attachment Outlook VBA and Custom Forms 10

Similar threads

Top