Results 1 to 2 of 2

Thread: VBA - Export outlook email body to excel

  1. #1

    VBA - Export outlook email body to excel



    Register for a FREE account, and/
    or Log in to avoid these ads!

    Hi,

    This code works fine exporting outlook email body to active excel workbook, but it is exporting all the contents into one cell
    I would need this to be populated in numbers of cells the data is. EXample attached screenshots

    Code:
    Sub GetSelectedItems()
        Dim myOlApp As New Outlook.Application
        Dim myOlExp As Outlook.Explorer
        'Dim myOlSel As Outlook.Selection
        Dim MsgTxt As String
        Dim x As Integer
        Set myOlExp = myOlApp.ActiveExplorer
        Set myOlSel = myOlExp.Selection
        For x = 1 To myOlSel.Count
            Worksheets(1).Cells(1, x) = myOlSel.Item(x).Body
        Next x
        Cells.WrapText = False
     End Sub

    Thanks,
    Hari Prasad
    Last edited by Bob Phillips; 2014-08-13 at 02:14 PM. Reason: Added VBA tags

  2. #2
    Conjurer WizzardOfOz's Avatar
    Join Date
    Sep 2013
    Location
    Australia
    Posts
    184
    Articles
    0
    Typically when you open Outlook only one mail item is selected. Also you probably want to swap rows and columns.

    Code:

    Sub GetSelectedItems()
    Dim myOlApp As New Outlook.Application
    Dim myOlExp As Outlook.Explorer
    'Dim myOlSel As Outlook.Selection
    Dim MsgTxt As String
    Dim x As Integer
    Set myOlExp = myOlApp.ActiveExplorer
    Set myOlSel = myOlExp.CurrentFolder.Items 'myOlExp.Selection
    For x = 1 To myOlSel.Count
    Worksheets(1).Cells(x,1) = myOlSel.Item(x).Body
    Next x
    Cells.WrapText = False
    End Sub

Posting Permissions

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