Wrox Programmer Forums
|
VB How-To Ask your "How do I do this with VB?" questions in this forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 5th, 2005, 08:40 PM
Registered User
 
Join Date: Oct 2004
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default MS Outlook 2000 procedure

How do I reference an additional mailbox other than the default inbox in MS Outlook 2000? I have written code to scan the emails of a folder and then copy the attachments to a desktop folder. However I dont know how to make this code scan anything but the default inbox.
Code is as follows:

Code:
Option Explicit

Sub getAttachments()

On Error GoTo error:

    Dim ns As NameSpace
    Dim Inbox As MAPIFolder
    Dim Item As Object
    Dim Atmt As Attachment
    Dim Filename As String
    Dim i As Integer

    Set ns = GetNamespace("MAPI")
    Set Inbox = ns.GetDefaultFolder(olFolderInbox)
    i = 0

    If Inbox.Items.Count = 0 Then
        MsgBox "There are no messages in the inbox.", vbInformation
        Exit Sub
    End If

    For Each Item In Inbox.Items
        For Each Atmt In Item.Attachments
            Filename = "C:\Documents and Settings\cunninb1\Desktop\Attachments\" & Atmt.Filename
            Atmt.SaveAsFile Filename
            i = i + 1
        Next Atmt
    Next Item

    If i > 0 Then
        MsgBox i & "attached files were found." & vbCrLf & _
            "They have been saved to C:\Documents and Settings\cunninb1\Desktop\Attachments\"
    Else
        MsgBox "No attachments were found."
    End If

GetAttachments_exit:
    Set Atmt = Nothing
    Set Item = Nothing
    Set ns = Nothing
    Exit Sub

Exit Sub

'------------------------------------------------------
error:
Dim msgerr As Integer
msgerr = MsgBox("The following error occured during saving of attachments from Outlook." & vbCr & _
    "Error Description: " & Err.Description & vbCr & _
    "Error Number: " & Err.Number, vbOKOnly + vbInformation)

'------------------------------------------------------

End Sub





Similar Threads
Thread Thread Starter Forum Replies Last Post
Database migration MS Access 2003 to MS SQL 2000 ayazhoda SQL Server 2000 3 April 23rd, 2007 11:38 AM
Outlook 2000 errors byron Pro VB.NET 2002/2003 3 December 1st, 2003 10:17 AM
Outlook 2000 errors byron VB.NET 2002/2003 Basics 0 August 28th, 2003 09:08 AM
Access 2000 and Outlook vaheh Access VBA 1 August 13th, 2003 03:18 PM
Outlook 2000 Automation byron Pro VB 6 4 July 10th, 2003 01:10 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.