Importing Outlook Body Data

jim may

Well-known Member
Joined
Jul 4, 2004
Messages
7,486
I'm creating an Excel Sys that will Open a series of Outlook e-mails (say 20) and bring them into a worksheet and paste the single string into A1:A20;

I initially have done this Using Excel 2003 and importing from a Outlook 2007 (What I use in my Office) inbox folder,
which seems to work fine;

I took my Excel 2003 Fule to a Client - who also runs (only) Excel 2003 and ran the same macro (The CLIENT RUNS Outlook 2003 (not 2007) ,, and I seem to be getting different results, INCLUDING some Error's like

R/T error '5':
Invalid procedure call or argument

with the offending line Activesheet.Cells ...(after the Do) as:

Do
Activesheet.cells(i, 1).value = _
Mid(stBody, LineBreak, InStr(LineBreak, stBody, Shr(10)) - LineBreak)
LineBreak = InStr(LineBreak + 1, stBody, Chr(10)) + 1
i = i + 1

Loop Until LineBreak = 0 Or LineBreak > Len(stBody)

Can anyone see why this could be happening?

TIA,
Jim
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
Here's a cleaned up version of same...

I'm creating an Excel Sys that will Open a series of Outlook e-mails (say 20) and bring the contenst of the Outlook.BODY into a worksheet and paste the single string into A1:A20;

I initially have done this Using Excel 2003 and importing from a Outlook 2007 (What I use in my Office) inbox folder,
which seems to work fine;

I took my Excel 2003 Fule to a Client - who also runs (only) Excel 2003 and ran the same macro (The CLIENT RUNS Outlook 2003 (not 2007) ,, and I seem to be getting different results, INCLUDING some Error's like

R/T error '5':
Invalid procedure call or argument

with the offending line Activesheet.Cells ...(after the Do) as:

Do
Activesheet.cells(i, 1).value = _
Mid(stBody, LineBreak, InStr(LineBreak, stBody, Chr(10)) - LineBreak)
LineBreak = InStr(LineBreak + 1, stBody, Chr(10)) + 1
i = i + 1

Loop Until LineBreak = 0 Or LineBreak > Len(stBody)

Can anyone see why this could be happening?
 
Upvote 0
Here is something which may help.
1) Open outlook. Select all the e-mail which you want information to be extracted from. e.g. Use Ctrl and click each mail so that multiple mails are selected. Minimize outlook.
2) Open new excel file. Goto VB Editor. Goto Tools - References. Check the box which says "Microsoft Outlook 11.0 Object Library". It may also say 10 or 9 sometimes. Click Ok.
This may be the reason why you are geiing the run time error.
3) In Excel VB Editor. Insert new module and run the code given below. It will extract the required information into Excel automatically. Hope this is what you want.
Once complete if required you can go back and uncheck "Microsoft Outlook 11.0 Object Library".

Code:
Sub GetMailDetails()
    Dim myOlApp As New Outlook.Application
    Dim myOlExp As Outlook.Explorer
    Dim myOlSel As Outlook.Selection
    Dim x As Integer
    Set myOlExp = myOlApp.ActiveExplorer
    Set myOlSel = myOlExp.Selection
    For x = 1 To myOlSel.Count
        Worksheets(1).Cells(x, 1) = myOlSel.Item(x).ReceivedTime
        Worksheets(1).Cells(x, 2) = myOlSel.Item(x).SenderName
        Worksheets(1).Cells(x, 3) = myOlSel.Item(x).Subject
        Worksheets(1).Cells(x, 4) = myOlSel.Item(x).Size
        Worksheets(1).Cells(x, 5) = myOlSel.Item(x).Body
    Next x
End Sub
 
Upvote 0

Forum statistics

Threads
1,225,392
Messages
6,184,706
Members
453,254
Latest member
topeb

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top