Get data from outlook into an excel worksheet
You can save Outlook emails to Excel by exporting them as a CSV (Comma Separated Value) file and then opening the file in Excel. Here's how to do it:
- Open Microsoft Outlook
- Select the email messages you want to export to Excel
- Right-click and choose "Save As"
- In the "Save As" dialog box, choose "CSV (Comma Separated Values)" as the file type.
- Give the file a name and choose a location to save it.
- Open the exported CSV file in Microsoft Excel.
Once the file is open in Excel, you can format and manipulate the data as needed.
Auto method
you can export Outlook email to Excel using Visual Basic (VB) scripting. The code will require using Microsoft Excel and Microsoft Outlook Object Libraries. This can be achieved by using the Outlook application's object model to access the email data and then using the Excel application's object model to create a new workbook and write the email data to it.
after you can see this window
Sub SaveOutlookEmails() Dim objOutlook As Object Dim objNamespace As Object Dim objFolder As Object Dim objMail As Object Dim objExcel As Object Dim objWorkbook As Object Dim objWorksheet As Object Dim intRow As Integer 'Create objects Set objOutlook = CreateObject("Outlook.Application") Set objNamespace = objOutlook.GetNamespace("MAPI") Set objFolder = objNamespace.Folders("mmdcreation@gmail.com").Folders("mmd1") Set objExcel = CreateObject("Excel.Application") Set objWorkbook = objExcel.Workbooks.Add Set objWorksheet = objWorkbook.Worksheets(1) 'Add headers to the Excel sheet objWorksheet.Cells(1, 1).Value = "Subject" objWorksheet.Cells(1, 2).Value = "From" objWorksheet.Cells(1, 3).Value = "To" objWorksheet.Cells(1, 4).Value = "Sent On" objWorksheet.Cells(1, 5).Value = "Body" 'Populate the data in the Excel sheet intRow = 2 For Each objMail In objFolder.Items objWorksheet.Cells(intRow, 1).Value = objMail.Subject objWorksheet.Cells(intRow, 2).Value = objMail.SenderName objWorksheet.Cells(intRow, 3).Value = objMail.To objWorksheet.Cells(intRow, 4).Value = objMail.SentOn objWorksheet.Cells(intRow, 5).Value = objMail.Body intRow = intRow + 1 Next 'Save the Excel file objWorkbook.SaveAs "C:\Users\Hp\Desktop\eml\New folder\test.csv" 'Release the objects objWorkbook.Close objExcel.Quit Set objMail = Nothing Set objFolder = Nothing Set objNamespace = Nothing Set objOutlook = Nothing End Sub
- Go to the VBA editor (press Alt + F11 in Excel)
- Go to Tools -> References
- Click the "Browse" button at the bottom of the References dialog
- Locate and select the file "Microsoft.Office.Interop.Excel.dll" (usually found in the "C:\Program Files\Microsoft Office\Root\OfficeXX" folder, where XX is the version number of Office installed on your computer)
- Click OK on the References dialog and then click OK again in the Browse dialog
This should add a reference to the Microsoft Excel Object Library in your VBA project, and you should no longer receive the "User Defined type not defined" error when trying to declare a variable of type "Excel.Application".
0 Comments