Consulting

Results 1 to 3 of 3

Thread: outlook vba

  1. #1

    outlook vba

    Hi,
    I tried to run the following code in outlook 2003. But i am getting error "Run time rror 424; object required" at line item.Body.Select. Could some one please help me what is the issue?

    Sub savedailyownership()
    Dim ns As NameSpace
    Dim Inbox As MAPIFolder
    Dim myitem As Outlook.MailItem
    Dim FileName As String
    Dim i As Integer
    Dim objSearchFolder As Outlook.MAPIFolder
    Dim item As Object
    Dim mai As MailItem

    Set ns = GetNamespace("MAPI")
    Set Inbox = ns.GetDefaultFolder(olFolderInbox)
    Set objSearchFolder = Inbox
    i = 0
    If Inbox.Items.Count = 0 Then
    MsgBox "Inbox is Empty", vbInformation, "Nothing Found"
    End If
    For Each item In Inbox.Items
    If item.Subject Like "Test outlook-Excel" Then
    'item.Display
    item.Body.Select
    Selection.Copy
    Dim xlApp As Object ' Excel.Application
    Dim xlWkb As Object ' Excel.Workbook
    Set xlApp = CreateObject("Excel.Application") ' New Excel.Application
    Set xlWkb = xlApp.Workbooks.Add
    xlApp.Visible = True
    xlApp.Workbooks.Add
    xlApp.Selection.Paste False, False, False
    End If
    Next
    End Sub

  2. #2
    VBAX Expert JP2112's Avatar
    Joined
    Oct 2008
    Location
    Astoria, NY
    Posts
    590
    Location
    Welcome to the board. Please format your VBA code using code tags like this:

    [vba]
    ' your code goes here
    [/vba]

    There is no Body.Select method. I think you are trying to copy and paste the body of an email into an Excel worksheet. If so, what you want to do is assign the Body property to a String variable, then set an Excel worksheet range to that variable. Ex:

    [vba]
    ' declare variable to hold email body
    Dim emailbody As String

    ' ... skip ahead ...

    If item.Subject Like "Test outlook-Excel" Then
    'item.Display
    emailbody = item.Body

    ' .... skip ahead ...

    xlApp.Worksheets(1).Range("a1").value = emailbody
    [/vba]
    Regards,
    JP

    Read the FAQ
    Getting free help on the web
    My website
    Please use [vba][/vba] tags when posting code

  3. #3
    Hi JP,

    thank you very much for your reply.

Posting Permissions

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