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
 
:(:(:(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
 
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.
 
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")
 
:)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
 
I am not allowed to upload a sample sheet... please help suggest
 
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.
 
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: 431
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.
 
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
 
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.
 
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
 
:)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
K vba code to auto download email into a specific folder in local hard disk as and when any new email arrives in Inbox/subfolder Outlook VBA and Custom Forms 0
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
T Why do Outlook Desktop 2021 tasks from my wife's email show up in my task pane? Using Outlook 2
A Opening a link from an email automatically Outlook VBA and Custom Forms 0
D Outlook 2021 New email reminder Using Outlook.com accounts in Outlook 0
Rupert Dragwater How do I remove an email ending with @gmail.com Using Outlook 4
M A plug in (or method) to keep email message formatting after it expires Using Outlook 1
L VBA to Triage Incoming Email Outlook VBA and Custom Forms 0
R Legacy Outlook on Mac Email Cache Using Outlook 0
P Email address auto-completes work fine on laptop, but no longer on desktop Using Outlook 3
S Create Outlook Task from Template and append Body with Email Body Outlook VBA and Custom Forms 4
H Copying email address(es) in body of email and pasting in To field Outlook VBA and Custom Forms 1
A Search folder and move the email Outlook VBA and Custom Forms 0
P VBA to add email address to Outlook 365 rule Outlook VBA and Custom Forms 0
farrissf Outlook 2016 Optimizing Email Searches in Outlook 2016: Seeking Insights on Quick Search vs Advanced Search Features Using Outlook 0
D Delete selected text in outgoing email body Outlook VBA and Custom Forms 0
F Graphics in email / Mac recipient garbled Using Outlook 0
D Outlook VBA forward the selected email to the original sender’s email ID (including the email used in TO, CC Field) from the email chain Outlook VBA and Custom Forms 2
Witzker Outlook 2019 Macro to seach in all contact Folders for marked Email Adress Outlook VBA and Custom Forms 1
E Outlook 365 Save Selected Email Message as .msg File - oMail.Delete not working when SEARCH Outlook VBA and Custom Forms 0
S Email Macros to go to a SHARED Outlook mailbox Draft folder...NOT my personal Outlook Draft folder Using Outlook 2
R Outlook 365 VBA AUTO SEND WITH DELAY FOR EACH EMAIL Outlook VBA and Custom Forms 0
G Print email attachments when hit subfolder Outlook VBA and Custom Forms 1
C Spam Email? Using Outlook 2
G Automatically delete email when a condition is met Outlook VBA and Custom Forms 1
E Save Selected Email Message as .msg File - digitally sign email doesn't works Outlook VBA and Custom Forms 1
S Email was migrated from GoDaddy to Microsoft exchange. We lost IMAP ability Exchange Server Administration 1
R Outlook 365 How to integrate a third-party app with Outlook to track email and sms? Using Outlook 2
S Paperclip icon shows without attachment in email under Sent folder Using Outlook 0
B Outlook 2019 Automatically move email after assigning category Using Outlook 4
Rupert Dragwater How to permanently remove an email address Using Outlook 9
F Auto changing email subject line in bulk Using Outlook 2
F Want to add second email to Outlook for business use Using Outlook 4
kburrows Outlook Email Body Text Disappears/Overlaps, Folders Switch Around when You Hover, Excel Opens Randomly and Runs in the Background - Profile Corrupt? Using Outlook 0
J Outlook 365 Outlook Macro to Sort emails by column "Received" to view the latest email received Outlook VBA and Custom Forms 0
A Outlook 2019 Help with forwarding email without mentioning the previous email sender. Outlook VBA and Custom Forms 0
J Macro to send email as alias Outlook VBA and Custom Forms 0
M Shift Delete doesn't delete email from server Using Outlook 3
K Incorporate selection from combobox into body of email Outlook VBA and Custom Forms 0
L Why are some email automatically going to "archive" Using Outlook 2
M Outlook Macro to save as Email with a file name format : Date_Timestamp_Sender initial_Email subject Outlook VBA and Custom Forms 0
B Outlook 2019 Custom Email form - Edit default email form Outlook VBA and Custom Forms 6
F Add a category before "Send an Email When You Add an Appointment to Your Calendar" Outlook VBA and Custom Forms 0
T Problem when requesting to view an email in a browser Using Outlook 0
J Outlook 365 Forward Email Subject to my inbox when new email arrive in shared inbox Using Outlook 0
HarvMan Archive Email Manually Using Outlook 1
L Fetch, edit and forward an email with VBA outlook Outlook VBA and Custom Forms 2
S New Email "From" box stopped working Using Outlook 0

Similar threads

Back
Top