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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

philcon (TechnicalUser) May 17, 20

Status
Not open for further replies.

philcon

Technical User
Feb 5, 2002
139
GB
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.[medal]



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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top