Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Save Outlook message with CDO

Status
Not open for further replies.

checkOut

Technical User
Joined
Oct 17, 2002
Messages
153
Location
NL
I get the code below from this Forum, it works like a charm thanx to Paul ;)
I need to save a message in an selected folder
In Outlook.Application you can do something like
.saveAs "C:\mail.msg",olMsg, but how its working in CDO?

Any help appreciated!

Gerard

Public Sub SelectOutlookItem()

Dim objSession As MAPI.Session
Dim objFolder As MAPI.Folder
Dim objMsgs As MAPI.Messages
Dim objMsg As MAPI.Message
Dim strProfile As String

'Write a function to get the default profile from the registry
'strProfile = fGetDefaultProfile
Set objSession = CreateObject("MAPI.Session")
With objSession
strProfile = "Server" & vbLf & "Clientname"
.Logon , , , False, , True, strProfile
'.Logon ShowDialog:=False, NewSession:=False
'General way to get any default folder
Set objFolder = .GetDefaultFolder(CdoDefaultFolderInbox)
'Inbox is also exposed directly as a property
'Set objFolder = .Inbox
End With
'Get the messages collection in the Inbox
Set objMsgs = objFolder.Messages
'Move through the messages collection
Set objMsg = objMsgs.GetLast
If objMsg Is Nothing Then
'Folder is empty
GoTo ExitSub
Else
' Do While Not objMsg Is Nothing
With objMsg
Debug.Print "Subject: " & .Subject
Debug.Print "Body: " & .Text
Debug.Print "Sent by: " & .Sender
Debug.Print "Received: " & CStr(.TimeReceived)
'Mark it as read
.Unread = False
.Saveas "H:\mail.msg", olMSg
End With
' Set objMsg = objMsgs.GetPrevious
' Loop
End If

GoTo ExitSub

ExitSub:
Set objMsg = Nothing
Set objMsgs = Nothing
Set objFolder = Nothing
Set objSession = Nothing

End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top