vba - outlook to excel email export quastion

hi all

i have a little question - i need to export some email fields to excel file -like TO,FROM..etc

but i need to export ONLY selected one..

ho to make outlook to export only selected one?


  • The following is code on how to read email using VB.NET.

    Dim otkApp As Outlook.Application = New Outlook.Application
    Dim otkMailItem = "IPM.Note"
    Dim otkNameSpace As Outlook.NameSpace = otkApp.GetNamespace("MAPI")
    Dim otkInboxFolder As Outlook.MAPIFolder = otkNameSpace.GetDefaultFolder _
    Dim otkMailItems As Outlook.Items = otkInboxFolder.Items

    Dim otkMessage As Outlook.MailItem
    Dim iCntr As Integer
    For iCntr = 1 To otkMailItems.Count
    If otkMailItems.Item(iCntr).MessageClass = otkMailItem Then
    otkMessage = otkMailItems.Item(iCntr)
    End If

    otkApp = Nothing
    otkNameSpace = Nothing
    otkMailItems = Nothing
    otkMessage = Nothing

    Here is the code to export data to Excel:

    Imports Microsoft.Office.Interop

    Dim XLSApp As New Excel.Application
    XLSApp.Visible = True
    Dim XLSWbks As Excel.Workbooks = XLSApp.Workbooks
    Dim XLSWbk As Excel.Workbook = XLSWbks.Add
    Dim XLSShts As Excel.Sheets = XLSWbk.Worksheets
    Dim XLSSht As Excel.Worksheet = XLSShts("Sheet1")

    XLSSht.Range("A1").Value = "This code was added using the Excel Object Model in VB.NET"

    Hope this helps!
  • This post has been deleted.
  • This post has been deleted.
  • maybe someone will need it
    thx anyway

    Sub MyFirstMacros()

    Set xlApp = GetObject(, "Excel.Application")

    Dim myItems As Object, myItem As Object, myAttachments As Object, myAttachment As Object
    Dim myOrt As String, myOlApp As New Outlook.Application, myOlExp As Outlook.Explorer
    Dim Selecttion_ As Outlook.Selection
    Dim bodyarray() As String
    Dim timearray() As String

    On Error Resume Next

    Set myOlExp = myOlApp.ActiveExplorer
    Set Selecttion_ = myOlExp.Selection

    Dim sh As Object, NextRow As Object
    Set sh = xlApp.ActiveSheet ' ???????? ???? Excel

    'for all items do...
    For Each myItem In Selecttion_

    bodyarray = Split(myItem.body, vbNewLine)
    timearray = Split(myItem.SentOn, " ")

    Set NextRow = sh.Range("B" & sh.Rows.Count).End(-4162).Offset(1) ' ?????? ????????????? ?????? ? ??????? C

    Dim body, time, fullbody As String

    body = bodyarray(0)
    time = timearray(1)
    fullbody = body & " " & "??????: " & myItem.To & " " & myItem.CC

    NextRow.Resize(, 4).Value = Array(time, time, myItem.Subject, fullbody)
    body = Nothing
    time = Nothing

    Set myItems = Nothing: Set myItem = Nothing
    Set myAttachments = Nothing: Set myAttachment = Nothing
    Set myOlApp = Nothing: Set myOlExp = Nothing: Set Selecttion_ = Nothing
    End Sub
  • Can I simply import the whole mail?
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!