Basic

Moderators: None (Apply to moderate this forum)
Number of threads: 1675
Number of posts: 4764

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
vba - outlook to excel email export quastion Posted by delphi_ on 1 Jan 2011 at 12:30 PM
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?
Report
Re: vba - outlook to excel email export quastion Posted by jga777 on 3 Jan 2011 at 9:24 AM
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
Report
Re: vba - outlook to excel email export quastion Posted by delphi_ on 4 Jan 2011 at 9:54 AM
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
Report
Re: vba - outlook to excel email export quastion Posted by readandbuy on 17 Jan 2011 at 12:25 AM
Can I simply import the whole mail?
Report
This post has been deleted. Posted by jga777 on 3 Jan 2011 at 9:26 AM
This post has been deleted.
Report
This post has been deleted. Posted by jga777 on 3 Jan 2011 at 9:28 AM
This post has been deleted.



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.