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

outlook 2003 -2007 need help getting emails in specific folder

Status
Not open for further replies.

DougP

MIS
Dec 13, 1999
5,985
US
I created this VBA code which works on the emails with attachments coming into the inbox.
how can I change it to look at a folder called lunches?
I have code to get lunches flde rbut don't know how to modify the
Code:
Sub GetAttachments()

   On Error GoTo GetAttachments_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)
    Set myNewFolder = myFolder.Folders("lunches") 
    
    i = 0
   
    For Each Item In Inbox.Items  ' change this to look at lunches folder
        
        For Each Atmt In Item.Attachments
        
           ' if excel save it and add email name to it
           Debug.Print Atmt.FileName
            If Right(Atmt.FileName, 3) = "xls" Then                  FileName = "S:\IT\aaa Email Attachments\" & Item.SenderEmailAddress & "|" & Atmt.FileName
                Atmt.SaveAsFile FileName
            End If
            i = i + 1
        Next Atmt
    Next Item
    
    MsgBox "All Excel Sheets saved", vbInformation, "Finished Saving..."
    
    
GetAttachments_exit:

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

    Select Case Err.Number
    
        Case Else
            MsgBox Err.Number & Err.Description, vbExclamation, "Error in sub GetAttachments"
            Resume 'GetAttachments_exit
            
    End Select
    
End Sub



DougP
[r2d2] < I Built one
 
Is Lunches a subfolder if your inbox? if so:
Code:
    Set Inbox = ns.GetDefaultFolder(olFolderInbox)
    Set [b][red]myFolder = Inbox[/red][/b].Folders("lunches") 
    For Each Item In [b][red]myFolder[/red][/b].Items
 


Doug,

You ought to be able to figure it out using the Watch Window...

faq707-4594

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
What about this ?
Set myNewFolder = ns.Folders(1).Folders("lunches")
For Each Item In myNewFolder.Items

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top