vba - outlook to excel email export quastion - Programmers Heaven

Howdy, Stranger!

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

Categories

vba - outlook to excel email export quastion

delphi_delphi_ Posts: 2Member
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?

Comments

  • jga777jga777 Posts: 9Member
    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 _
    (Outlook.OlDefaultFolders.olFolderInbox)
    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)
    Console.WriteLine(iCntr)
    Console.WriteLine(otkMessage.SenderName)
    Console.WriteLine(otkMessage.Subject)
    Console.WriteLine(otkMessage.ReceivedTime)
    Console.WriteLine(otkMessage.Body)
    Console.WriteLine("______________________________")
    End If
    Next

    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"
    XLSSht.SaveAs("G:my2007ExcelWorkbook.xlsx")



    Hope this helps!
    -Jaime
  • jga777jga777 Posts: 9Member
    This post has been deleted.
  • jga777jga777 Posts: 9Member
    This post has been deleted.
  • delphi_delphi_ Posts: 2Member
    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
    Next



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