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

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.
Thread starter Similar threads 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
D Received emails show only red X's no images - Email set for HTML. Prevent download of images is OFF Using Outlook 6
A Copy email from external server, rather than totall download it Using Outlook 1
J cannot download pop3 email from Comcast after latest Microsoft update Using Outlook 5
G Configure outlook to download hyperlinked images in email automatically to PST Using Outlook 2
T I am looking for a Microsoft Outlook Email Stationery download? Using Outlook 5
A Outlook 2010- Viewing HTML email opens File Download dialogs Using Outlook 2
P Had Outlook Connector working, it asked for upgrade repeatedly. Uninstalled and tried to download-reinstall and it doesn't read my live.com email or Using Outlook 5
N email does not appear in inbox while downloading and at the end of the download it says an error occurred Using Outlook 2
S "File Download" Dialog open every time I click on an email to read it. Using Outlook 8
F Can I download my Sent emails off my email server just like you do for your Inbox? Using Outlook 1
H I cannot download images with email. Using Outlook 2
T Spouse's account does not connect and download email upon startup of Outlook Using Outlook 3
S Cannot download my email Using Outlook 1
A Pictures and graphics in email do not download Using Outlook 5
D Sending email from Office 365 alias in Outlook Using Outlook 4
S Macro or plug-in to see if specific person was included in this email Outlook VBA and Custom Forms 3
S Body text of Email from invite date/time Outlook VBA and Custom Forms 8
R Outlook 2010 How do you export 2 email Accounts' 2010 Inbox Files to new computer (2019)? Using Outlook 1
R Auto display of new email does not work on non-default account Outlook VBA and Custom Forms 0
J Automatically forward email and apply template Outlook VBA and Custom Forms 0
L Outlook saved email templates Using Outlook 1
B VBA to convert email to task, insert text of email in task notes, and attach copy of original email Outlook VBA and Custom Forms 4
T How can you include Junk Email in Search Results like you can include Deleted Items? Using Outlook 3
B Extracting email addresses from a folder - how to also get the name of the person the address is for? Using Outlook 5
W Replyin to the reply-to email address Outlook VBA and Custom Forms 0
E How to display "Change Folder" in Change Default Email Delivery Location in Exchange Outlook 2016 Using Outlook 1
M Extract all links from Outlook email, send to Excel Using Outlook 2
O Forward a email with modified body Automatically. Outlook VBA and Custom Forms 0
B Outlook 2003 email sending & receiving suddenly stopped working Using Outlook 3
R List folders in a combo box + select folder + move emails from inbox to that folder + reply to that email Outlook VBA and Custom Forms 1
O Email not leaving Outbox when using Excel VBA to sync Outlook account Outlook VBA and Custom Forms 4
T The non-email functions Using Outlook 8
P Outlook 2013 Word Share doc as Email Attachment now brings up Eudora. Using Outlook 1
C How to rename subject line and forward the email Outlook VBA and Custom Forms 2
R Help Revising VBA macro to delete email over different time span Outlook VBA and Custom Forms 0
J Sent Items Folder NOT Showing Correct From Email Address Using Outlook 0
J Outlook Reply > From > Other Email Address... > Address Not Showing in Sent Items... From Email Outlook VBA and Custom Forms 0
T Column to display which email alias a message was sent to Outlook VBA and Custom Forms 6
Marc2019 Need help please! Cannot Setup my outlook email account on my Mac Outlook 2011 Using Outlook.com accounts in Outlook 2
HarvMan Hotmail - Sending email is undeliverable Using Outlook 4
R Error when trying to forward current email item Outlook VBA and Custom Forms 7
H In outlook 365 POP mail Inbox, email takes a long time or never arrives. Using Outlook 1
D Can Exchange Admin Center create a pst for users email/contacts/calendar? Exchange Server Administration 0
T After I send a new email, it remains in the Draft folder Using Outlook.com accounts in Outlook 3
P OWA Settings->Calendar->Events from Email; Setting changes do not hold Using Outlook 1
S How to export urls from email to excel and check the status of the url ? New Slipstick.com Articles 6
P Auto Insert Current Date or Time into Email Subject Outlook VBA and Custom Forms 2
Similar threads


















































Top