PDA

View Full Version : I don't even know where to start



Jackyll
07-29-2014, 03:01 PM
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.

Jackyll
07-29-2014, 05:17 PM
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.

Bob Phillips
07-30-2014, 01:50 AM
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

Jackyll
07-30-2014, 07:50 AM
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?

westconn1
07-30-2014, 02:36 PM
is there anyway to separateyes of course

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