S
Stacey Levine
I have an inbox that gets messages regularly. The inbox is never opened. I
need a process that logs into that inbox, saves the attachmnets and then
moves the messages to another folder. I can do the below code on my inbox -
but can't figure out how to specify another inbox. I can not set up another
profile. I just need to specify the user/password information and have it
open that box. I am open to MAPI, or CDO.. or any way to do this. Thanks
Stacey
Dim oOutlook As Outlook.Application
Dim oNs As Outlook.NameSpace
Dim oFldr As Outlook.MAPIFolder
Dim oMessage As Object
Dim sPathName As String
Dim oAttachment As Outlook.Attachment
Dim iCtr As Integer
Dim iAttachCnt As Integer
On Error GoTo ErrHandler
Set oOutlook = New Outlook.Application
Set oNs = oOutlook.GetNamespace("MAPI")
Set oFldr = oNs.GetDefaultFolder(olFolderInbox)
For Each oMessage In oFldr.Items
With oMessage.Attachments
iAttachCnt = .Count
If iAttachCnt > 0 Then
For iCtr = 1 To iAttachCnt
MsgBox (.Item(iCtr).FileName)
' .Item(iCtr).SaveAsFile sPathName _
' & .Item(iCtr).FileName
Next iCtr
End If
End With
DoEvents
Next oMessage
SaveAttachments = True
ErrHandler:
MsgBox "Error : " & Err.Description
Set oMessage = Nothing
Set oFldr = Nothing
Set oNs = Nothing
Set oOutlook = Nothing
End Function
need a process that logs into that inbox, saves the attachmnets and then
moves the messages to another folder. I can do the below code on my inbox -
but can't figure out how to specify another inbox. I can not set up another
profile. I just need to specify the user/password information and have it
open that box. I am open to MAPI, or CDO.. or any way to do this. Thanks
Stacey
Dim oOutlook As Outlook.Application
Dim oNs As Outlook.NameSpace
Dim oFldr As Outlook.MAPIFolder
Dim oMessage As Object
Dim sPathName As String
Dim oAttachment As Outlook.Attachment
Dim iCtr As Integer
Dim iAttachCnt As Integer
On Error GoTo ErrHandler
Set oOutlook = New Outlook.Application
Set oNs = oOutlook.GetNamespace("MAPI")
Set oFldr = oNs.GetDefaultFolder(olFolderInbox)
For Each oMessage In oFldr.Items
With oMessage.Attachments
iAttachCnt = .Count
If iAttachCnt > 0 Then
For iCtr = 1 To iAttachCnt
MsgBox (.Item(iCtr).FileName)
' .Item(iCtr).SaveAsFile sPathName _
' & .Item(iCtr).FileName
Next iCtr
End If
End With
DoEvents
Next oMessage
SaveAttachments = True
ErrHandler:
MsgBox "Error : " & Err.Description
Set oMessage = Nothing
Set oFldr = Nothing
Set oNs = Nothing
Set oOutlook = Nothing
End Function