Consulting

Results 1 to 5 of 5

Thread: I don't even know where to start

  1. #1
    VBAX Newbie
    Joined
    Jul 2014
    Posts
    3
    Location

    Angry I don't even know where to start

    first off, thank you for even reading this. I have ZERO programming knowledge but I am fairly sure this can be done.

    I have about 73 emails each has the same information in the body of the email that i need taken out of the body of the email and put into an excel spreadsheet. The entire body looks like this:

    Wireless Agent or Retail Location
    Wireless Customer Name
    Wireless Phone or Account Number
    New Wireless Customer Name
    New Wireless Phone or Account Number

    Obivously with customer information in them but I don't want to post that online for everyone to see lol.

    BUT how code, if any, can i plainly copy and paste into VBA to make it do what i want to do?

    I've done a lot of googling around and found nothing in reference to what I'm trying to do, if you know of any PLEASE point me in the right direction. As it stands right now i have to go through each email individually and copy/paste one piece of information at a time into a spreadsheet.

    Any help would be GREATLY appreciated.

  2. #2
    VBAX Newbie
    Joined
    Jul 2014
    Posts
    3
    Location
    OK i found this code:

    Sub Extract()
     On Error Resume Next
     Set myOlApp = Outlook.Application
     Set mynamespace = myOlApp.GetNamespace("mapi")
     Set myfolder = myOlApp.ActiveExplorer.CurrentFolder
     
    Set xlobj = CreateObject("excel.application.14")
     xlobj.Visible = True
     xlobj.Workbooks.Add
     xlobj.Worksheets("Sheet1").Name = "Almost Done"
     
    'Set the header
     xlobj.Range("a" & 1).Value = "To"
     xlobj.Range("a" & 1).Font.Bold = "True"
     xlobj.Range("b" & 1).Value = "Date"
     xlobj.Range("b" & 1).Font.Bold = "True"
     xlobj.Range("c" & 1).Value = "email body"
     xlobj.Range("c" & 1).Font.Bold = True
    
    
     
    For i = 1 To myfolder.Items.Count
      Set myitem = myfolder.Items(i)
      msgtext = myitem.Body
       
      xlobj.Range("a" & i + 1).Value = myitem.To
      xlobj.Range("b" & i + 1).Value = myitem.ReceivedTime
      xlobj.Range("c" & i + 1).Value = msgtext
     
    
    
     Next
     End Sub
    and it does what I want to an extent, but it just takes the body of the email and puts it into one cell instead of sectioning it out by field like i need it to.
    Last edited by Bob Phillips; 07-30-2014 at 01:14 AM. Reason: Added VBA tags

  3. #3
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Sub Extract()
    
        On Error Resume Next
        Set myOlApp = Outlook.Application
        Set mynamespace = myOlApp.GetNamespace("mapi")
        Set myfolder = myOlApp.ActiveExplorer.CurrentFolder
         
        Set xlobj = CreateObject("excel.application.14")
        xlobj.Visible = True
        xlobj.Workbooks.Add
        xlobj.Worksheets("Sheet1").Name = "Almost Done"
         
         'Set the header
        xlobj.Range("a" & 1).Value = "To"
        xlobj.Range("a" & 1).Font.Bold = "True"
        xlobj.Range("b" & 1).Value = "Date"
        xlobj.Range("b" & 1).Font.Bold = "True"
        xlobj.Range("c" & 1).Value = "email body"
        xlobj.Range("c" & 1).Font.Bold = True
         
        nextrow = 1
        For i = 1 To myfolder.Items.Count
        
            Set myitem = myfolder.Items(nextrow)
            msgtext = myitem.Body
             
            xlobj.Range("A" & nextrow + 1).Value = myitem.To
            xlobj.Range("B" & nextrow + 1).Value = myitem.ReceivedTime
            msgarray = Split(msgtext, vbNewLine)
            For ii = LBound(msgarray) To UBound(msgarray)
            
                nextrow = nextrow + 1
                xlobj.Range("C" & nextrow).Value = msgarray(ii)
            Next ii
        Next
    End Sub
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  4. #4
    VBAX Newbie
    Joined
    Jul 2014
    Posts
    3
    Location
    This is AWESOME that in it self has saved me about a week of copy and pasting individual pieces of information, thank you SO MUCH. Now, I may be getting picky, and if it can't be done i'm happy with this, currently it takes the entire line with it to the body
    Current Wireless Customer Name * Customer Name, is there anyway to separate the "current wireless customer name" and the "customer name" into separate cells in excel with this code?

  5. #5
    is there anyway to separate
    yes of course

    post a sample attachment with data (change details)
    and a sample of how you want the result

Posting Permissions

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