I have little to no experience using VBA so I found a sample of code that would allow me to select a folder in Outlook and export that data into Excel. The folder selection box pops up consistently and it opens the file I selected, so that is good. I have tried doing so many things to the code to get it to function properly, but to no avail. One attempt where I removed all of the error handling stuff allowed me to export certain folders, but I still got error messages for some of the other ones. I'm thinking it might have something to do with "Dim msg As Outlook.MailItem". Every time I try to select a folder it says "There are no mail messages to export". I have received error messages: 13, 438, and 50290. The code is posted below. Your help is greatly appreciated.
-Eric - Sub ExportToExcel()
-
On Error GoTo ErrHandler
-
Dim appExcel As Excel.Application
-
Dim wkb As Excel.Workbook
-
Dim wks As Excel.Worksheet
-
Dim rng As Excel.Range
-
Dim strSheet As String
-
Dim strPath As String
-
Dim intRowCounter As Integer
-
Dim intColumnCounter As Integer
-
Dim msg As Outlook.MailItem
-
Dim nms As Outlook.NameSpace
-
Dim fld As Outlook.MAPIFolder
-
Dim itm As Object
-
strSheet = "Copy of Archive Completed Messages.xlsx"
-
strPath = "C:\Users\Documents\"
-
strSheet = strPath & strSheet
-
Debug.Print strSheet
-
-
Set nms = Application.GetNamespace("MAPI")
-
Set fld = nms.PickFolder
-
-
If fld Is Nothing Then
-
MsgBox "There are no mail messages to export", vbOKOnly, "Error"
-
Exit Sub
-
ElseIf fld.DefaultItemType <> olMailItem Then
-
MsgBox "There are no mail messages to export", vbOKOnly, "Error"
-
Exit Sub
-
ElseIf fld.Items.Count = 0 Then
-
MsgBox "There are no mail messages to export", vbOKOnly, "Error"
-
Exit Sub
-
End If
-
-
Set appExcel = CreateObject("Excel.Application")
-
appExcel.Workbooks.Open (strSheet)
-
Set wkb = appExcel.ActiveWorkbook
-
Set wks = wkb.Sheets(1)
-
wks.Activate
-
MsgBox "There are no mail messages to export", vbOKOnly, "Error"
-
appExcel.Application.Visible = True
-
-
-
For Each itm In fld.Items
-
intColumnCounter = 1
-
Set msg = itm
-
intRowCounter = intRowCounter + 1
-
Set rng = wks.Cells(intRowCounter, intColumnCounter)
-
rng.Value = msg.To
-
intColumnCounter = intColumnCounter + 1
-
Set rng = wks.Cells(intRowCounter, intColumnCounter)
-
rng.Value = msg.SenderName
-
intColumnCounter = intColumnCounter + 1
-
Set rng = wks.Cells(intRowCounter, intColumnCounter)
-
rng.Value = msg.LastModificationDate
-
intColumnCounter = intColumnCounter + 1
-
Next itm
-
Set appExcel = Nothing
-
Set wkb = Nothing
-
Set wks = Nothing
-
Set rng = Nothing
-
Set msg = Nothing
-
Set nms = Nothing
-
Set fld = Nothing
-
Set itm = Nothing
-
Exit Sub
-
ErrHandler: If Err.Number = 1004 Then
-
MsgBox strSheet & " doesn't exist", vbOKOnly, "Error"
-
Else
-
MsgBox Err.Number & "; Description: ", vbOKOnly, "Error"
-
End If
-
Set appExcel = Nothing
-
Set wkb = Nothing
-
Set wks = Nothing
-
Set rng = Nothing
-
Set msg = Nothing
-
Set nms = Nothing
-
Set fld = Nothing
-
Set itm = Nothing
-
End Sub
3 2130
Eric, I am confused.
This has been posted on the Access Forum, and yet deals with Excel
Your Question is unclear. Do yo want to Export from Outlook and Import into Excel. or Export from Excel and Import into Outlook.
The info I gave you on a previous post just links an Outlook folder to Access so gives the illusion that you are Exporting from Outlook and Importing into Excel.
The 2 queries then put that data into a table.
Excel is not my forte, but I suspect you can do something similar, but I wouldn't be surprised if you get lots of duplicate messages.
Phil
Oops! Sorry about that Phil. Thank you for being the only person to respond to me on these things. So, what my boss wants is the report in access, which you helped me with and works great. However, he wants me to create a code to export Outlook folders directly into Excel so that they can run additional analysis on the emails.
Eric
Why Excel & not Access?
Phil
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Paolo |
last post by:
Friends,
I need help with some code to export different tables to a single
spreadsheet in Excel.
My excel file is named REPORT and the spreadsheet is named CLIENTS.
I do have the code to export...
|
by: Keon |
last post by:
Hoi,
I'm using a database with alot of records in 1 table (more than 3000). If i
want to export this table to excel i only get it till record 2385. Do
someone know how i can solve this...
|
by: Siu |
last post by:
Hi,
I use the following code to export and import a file Excel from resp. into a
Web page with the following code:
//EXPORT
Response.Clear();
Response.Buffer = true;
Response.ContentType =...
|
by: JJ_377 |
last post by:
I made a user control to gather usa address information and would like
to know why the following doesn't work (I am assigning the valid of
textbox in a second instance of the control from the first...
|
by: Joseph Burton |
last post by:
I'm trying to find the code to export calendar data to excel just like the
wizard does in outlook.
I have been searching the internet left and right and can't find anything.
Can this be done...
|
by: Simon |
last post by:
Dear reader,
With the export command you can export a query to Excel.
By activate this command a form pop's up with the following text:
|
by: dino011279 |
last post by:
Hello everyone ,
Could any one please tell me the Vb script to export data from Outlook task onto excel?
Regards
Dino
|
by: johnlim20088 |
last post by:
Hi,
Hi someone can help me on this?
Currently I have a Listdata.aspx page with datagrid, I wish to export my datagrid content to excel with following code ( with button export click event):-
...
|
by: budigila |
last post by:
Hiya peeps,
Okies, I have been trying to work this out for a while now to no avail... I am a beginner to this whole coding thing but have made great strides in my project. Basically what I am...
|
by: =?Utf-8?B?U2hhbQ==?= |
last post by:
Hai all,
In my application, I need to Export webpage things into hard drive. I am
using gridview, and i export all things(with the help of some sites) into
excel except images.
Please, Can...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |