- Joined
- Oct 16, 2009
- Messages
- 1
- Reaction score
- 0
Hello - Need your help with formulating a VBS code to look at a custom folder in Outlook 2003. I need the macro to look into a my custom folder called "PHOTOSforRelease" not teh default "Inbox". Take a look at my code and assist me with the "Set Inbox" line - I have attached a graphic so you can see the my Outlook setup. THANKS!!!
Here is the code as I have it:
Sub GetAttachments()
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 PHOTOSforRelease.Items.Count = 0 Then
MsgBox "There are no messages in the folder.", vbInformation, _
"Nothing Found"
Exit Sub
End If
For Each Item In PHOTOSforRelease.Items
For Each Atmt In Item.Attachments
FileName = "W:\Macro Test\" & Atmt.FileName
Atmt.SaveAsFile FileName
i = i + 1
Next Atmt
Next Item
If i > 0 Then
MsgBox "I found " & i & " attached files." _
& vbCrLf & "I have saved them into the W:\Macro Test folder." _
& vbCrLf & vbCrLf & "It's all good!.", vbInformation, "Finished!"
Else
MsgBox "Hey butt-hole, I didn't find any attached files in your messages.", vbInformation, _
"Finished!"
End If
GetAttachments_exit:
Set Atmt = Nothing
Set Item = Nothing
Set ns = Nothing
Exit Sub
End Sub
Here is the code as I have it:
Sub GetAttachments()
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 PHOTOSforRelease.Items.Count = 0 Then
MsgBox "There are no messages in the folder.", vbInformation, _
"Nothing Found"
Exit Sub
End If
For Each Item In PHOTOSforRelease.Items
For Each Atmt In Item.Attachments
FileName = "W:\Macro Test\" & Atmt.FileName
Atmt.SaveAsFile FileName
i = i + 1
Next Atmt
Next Item
If i > 0 Then
MsgBox "I found " & i & " attached files." _
& vbCrLf & "I have saved them into the W:\Macro Test folder." _
& vbCrLf & vbCrLf & "It's all good!.", vbInformation, "Finished!"
Else
MsgBox "Hey butt-hole, I didn't find any attached files in your messages.", vbInformation, _
"Finished!"
End If
GetAttachments_exit:
Set Atmt = Nothing
Set Item = Nothing
Set ns = Nothing
Exit Sub
End Sub