philcon (TechnicalUser) May 17, 2002
Hi All
The following piece of code is SUPPOSED to process (detach attachments) each message in an outlook folder, and then move the message to an alternative folder. Almost works fine, but each time I run it, it leaves one message unprocessed. This seems to be the last bug in quite a large project for me, so a foaming pint of lager to whoever can help.
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
Dim strSubject As String
On Error GoTo ErrHandler
sPathName = "c:\phil\"
Set oOutlook = New Outlook.Application
Set oNs = oOutlook.GetNamespace("MAPI"
Set oFldr = oNs.GetDefaultFolder(olFolderInbox).Folders("briefs"
For Each oMessage In oFldr.Items
If oMessage.Subject = "DTGBBF New Brief" Then
With oMessage.Attachments
iAttachCnt = .Count
If iAttachCnt > 0 Then
For iCtr = 1 To iAttachCnt
.Item(iCtr).SaveAsFile sPathName _
& .Item(iCtr).FileName
Next iCtr
End If
End With
oMessage.Move oFldr.Folders("processed"
End If
DoEvents
Next oMessage
Hi All
The following piece of code is SUPPOSED to process (detach attachments) each message in an outlook folder, and then move the message to an alternative folder. Almost works fine, but each time I run it, it leaves one message unprocessed. This seems to be the last bug in quite a large project for me, so a foaming pint of lager to whoever can help.
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
Dim strSubject As String
On Error GoTo ErrHandler
sPathName = "c:\phil\"
Set oOutlook = New Outlook.Application
Set oNs = oOutlook.GetNamespace("MAPI"
Set oFldr = oNs.GetDefaultFolder(olFolderInbox).Folders("briefs"
For Each oMessage In oFldr.Items
If oMessage.Subject = "DTGBBF New Brief" Then
With oMessage.Attachments
iAttachCnt = .Count
If iAttachCnt > 0 Then
For iCtr = 1 To iAttachCnt
.Item(iCtr).SaveAsFile sPathName _
& .Item(iCtr).FileName
Next iCtr
End If
End With
oMessage.Move oFldr.Folders("processed"
End If
DoEvents
Next oMessage