Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Geo Geo is offline
external usenet poster
 
Posts: 66
Default Excel97 macro to archive Outlook mailbox

I need a macro that will be able to read email from Outlook and create an
archive PST file according to certain date criteria.

I have a bit of code that will access my inbox and tell me the subject
headers of the mails within certain dates. However, I need to access the
inbox of another mailbox that I have access to and does not contain my
default inbox.

So first question is: How do I get the macro to access the inbox of another
Mailbox?

Secondly, what command do I need to use to make the PST file?

I'm limited to Excel97 and Outlook97.

Here is my function as it stands at the moment:

Private Function ArchiveEmail(StartDate As Date, EndDate As Date) As Boolean
Dim returnState As Boolean
Dim olApp As Outlook.Application
Dim olEmail As Outlook.MailItem
Dim EmailItemCount As Integer
Dim OLF As Outlook.MAPIFolder
Dim subjectLog As String
Dim em

'assume success
returnState = True

'set the error trap
On Error Resume Next 'GoTo Connect_Error

Set olApp = GetObject("Outlook.Application")
If Err < 0 Then
'outlook not running so start it
Set olApp = CreateObject("outlook.application")
End If

Set OLF = GetObject("",
"Outlook.Application").GetNamespace("MAPI").GetDef aultFolder(olFolderInbox)
EmailItemCount = OLF.Items.Count

subjectLog = "Email count: " & EmailItemCount
Set olEmail = olApp.Item(olMailItem)
For Each em In OLF.Items
With em
If .ReceivedTime <= StartDate _
And .ReceivedTime = EndDate _
Then
subjectLog = subjectLog & vbCrLf & .Subject
End If
End With
Next

MsgBox subjectLog

Archive_Exit:
ArchiveEmail = returnState
Exit Function

Connect_Error:
returnState = False
MsgBox Err.Number & ": " & Err.Description, vbOKOnly +
vbApplicationModal + vbCritical, "Archive Email"
Resume Archive_Exit
End Function

-------

Cheers,

Geo

--
Quacking Eck!
It's The Duck!
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Auto Forward in Mailbox Suleman[_2_] Excel Discussion (Misc queries) 4 August 25th 09 03:41 PM
UNDO in EXCEL97 macro david[_9_] Excel Programming 2 July 12th 04 06:48 AM
why doesn't excel97 winNT vba macro code work in excel2002 winXP??? m a Excel Programming 4 June 23rd 04 06:20 PM
excel97: filtering out the zeros macro Joe[_21_] Excel Programming 2 June 16th 04 02:35 PM
Archive Macro Michael[_30_] Excel Programming 2 April 20th 04 12:03 AM


All times are GMT +1. The time now is 05:41 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"