Gossamer Forum
Home : General : Chit Chat :

eoutlook - Can't save???

Quote Reply
eoutlook - Can't save???
C

Need help!!!!!

I am trying to pull only fields TO, SUBJECT AND SENT DATE from Microsoft Server folder from a particular subfolder and collect information onto access or excel or text.
I am asked to produce a report of all item sent in year 2004 and give a count of emails by month.
New to coding in outlook
Need help.
Can you please check the code and let me know where I went wrong.

Private Sub ProcessInbox_Click()
'' Folder in Microsoft Exchange Server folder
Dim oOutlookApp As Outlook.Application
Dim oFolder1 As Outlook.MAPIFolder
Dim oFolder2 As Outlook.MAPIFolder
Dim oMsgItem As Outlook.MailItem
Dim iMsgCount As Integer
Dim strFolderName As String

' get reference to personal folder
Set oOutlookApp = CreateObject("Outlook.Application")
Set oFolder1 = Session.Folders("Personal Folders")
Set oFolder2 = oFolder1.Folders("PMA")

iMsgCount = 0

For Each oMsgItem In oFolder2.Items
With oMsgItem
If .SenderName = "PMA" Or .SenderName = "PAM" Then
If Date >= #1/1/2004# And Date <= #1/31/2004# Then
Debug.Print .To
Debug.Print .Subject
Debug.Print .Sent

iMsgCount = iMsgCount + 1
'save in an excel or text file
.SaveAs "c:\message.txt"

End If
End If
End With
DoEvents
Next oMsgItem

Set oMsgItem = Nothing
Set oFolder1 = Nothing
Set oFolder2 = Nothing
Set oOutlookApp = Nothing
End Sub