+ Reply to Thread
Results 1 to 1 of 1

Copy from email to excel

Hybrid View

  1. #1
    Registered User
    Join Date
    12-05-2013
    Location
    Singapore
    MS-Off Ver
    Excel 2010
    Posts
    1

    Copy from email to excel

    Hi All,

    I'm not an expert in VBA, most of the time I just record macro and edit from there.
    I need an excel macro to copy from all the emails in a folder to my excel and found some relevant code online which I have amended a bit.
    The below code runs but what is baffling me is the received details of the email does not match the body.
    Can you please kindly help enlighten me? Thank you so much in advance.. =)


    ---------------------------------------------------------------

    Sub test()
    
    Dim olApp As Object
    Dim olNS As Object
    Dim olFldr As Object
    Dim olMail As Object
    Dim i As Integer
    Dim j As Long
    Dim abody() As String
    Dim Cnt As Long
    Dim arrData() As Variant
    
    Set olApp = CreateObject("Outlook.Application")
    Set olNS = olApp.GetNamespace("MAPI")
    Set olFldr = olNS.GetDefaultFolder(olFolderInbox).Folders("temp")
    
    Cnt = 0
    For Each olMail In olFldr.Items
    On Error GoTo errorhandler
    Cnt = Cnt + 1
    
    abody = Split(olFldr.Items(Cnt).Body, vbNewLine)
    
    For j = 0 To UBound(abody)
    Sheet1.Cells(65000, 1).End(xlUp).Offset(1, 0).Value = abody(j)
    Next
    
    ReDim Preserve arrData(1 To 1, 1 To Cnt)
    arrData(1, Cnt) = olMail.ReceivedTime
    Cells(1, 1).Value = arrData(1, Cnt)
    
    Cells(1, 1).NumberFormat = "dd/mm/yyyy hh:mm:ss AM/PM"
    
    olFldr.Items(Cnt).Move olNS.GetDefaultFolder(6).Folders("Processed")
    
    Next
    
    Set olApp = Nothing
    Set olNS = Nothing
    Set olFldr = Nothing
    
    errorhandler:
    Application.CutCopyMode = False
    Set olApp = Nothing
    Set olNS = Nothing
    Set olFldr = Nothing
    Exit Sub
    
    End Sub
    Moderator Note:

    Pls use code tags around your code next time as per forum rules.
    Last edited by Fotis1991; 12-06-2013 at 06:41 AM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Copy and paste Excel range as picture into Outlook email body using excel vba
    By ExcelDoc in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 01-17-2016, 09:29 PM
  2. Replies: 0
    Last Post: 02-21-2013, 04:46 AM
  3. Macro to copy email to excel not in correct format.
    By josh640557 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-15-2013, 05:53 PM
  4. Replies: 2
    Last Post: 08-01-2012, 02:47 PM
  5. Copy an excel to an email template using VBA
    By mhuddles1981 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-06-2010, 12:34 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1