Outlook OutLook Subject Test

Joined
Feb 26, 2010
Messages
1
Reaction score
0
Hi everyone, rookie here messing around in a VBA module with Outlook. Im stumped on how to test the subject on email with attachments in my inbox. The code I have below works, as for as saving the attached files, but I need to test the Subject of the email to save the attached file to the correct folder

Code:
[font=Arial][size=2]Sub SaveAttsPD()[/size][/font]
 
[font=Arial][size=2]On Error GoTo Att_err[/size][/font]
[font=Arial][size=2][/size][/font] 
[font=Arial][size=2]Dim ns As NameSpace[/size][/font]
[font=Arial][size=2]Dim Inbox As MAPIFolder[/size][/font]
[font=Arial][size=2]Dim Item As Object[/size][/font]
[font=Arial][size=2]Dim Atmt As Attachment[/size][/font]
[font=Arial][size=2]Dim FileName As String[/size][/font]
[font=Arial][size=2]Dim i As Integer[/size][/font]
[font=Arial][size=2]Dim s As String[/size][/font]
 

 
[font=Arial][size=2]Set ns = GetNamespace("MAPI")[/size][/font]
[font=Arial][size=2]Set Inbox = ns.GetDefaultFolder(olFolderInbox)[/size][/font]
[font=Arial][size=2][/size][/font] 
[font=Arial][size=2]i = 0[/size][/font]
 

[font=Arial][size=2]If Inbox.Items.Count = 0 Then[/size][/font]
[font=Arial][size=2] MsgBox "There are no messages in the Inbox"[/size][/font]
 [font=Arial][size=2]Exit Sub[/size][/font]
[font=Arial][size=2]End If[/size][/font]
 

 

 
[font=Arial][size=2]For Each Item In Inbox.Items[/size][/font]
[font=Arial][size=2] For Each Atmt In Item.Attachments[/size][/font]
  [font=Arial][size=2]FileName = "d:\ADP\ADP PD Files\" & Atmt.FileName[/size][/font]
[font=Arial][size=2]	Atmt.SaveAsFile FileName[/size][/font]
 [font=Arial][size=2]	 i = i + 1[/size][/font]
  [font=Arial][size=2]Next Atmt[/size][/font]
 [font=Arial][size=2]Next Item[/size][/font]
  
[font=Arial][size=2]If i > 0 Then[/size][/font]
 [font=Arial][size=2]MsgBox "I found " & i & " attached files." _[/size][/font]
 [font=Arial][size=2]& vbCrLf & "I haved saved these attached files into D:\ADP\ADP PD Files folder."[/size][/font]
[font=Arial][size=2]Else[/size][/font]
[font=Arial][size=2]  MsgBox "I didn't find any attached files in your emails"[/size][/font]
[font=Arial][size=2]End If[/size][/font]
 

 
[font=Arial][size=2]Att_err:[/size][/font]
 

 
[font=Arial][size=2]End Sub[/size][/font]
[font=Arial]
[/font]



need some hints on how to this
if subject = "Punch Detail Report" then FileName = "d:\ADP\ADP PD Files\" & Atmt.FileName
if subject = "Employee Schedule" then FileName = "d:\ADP\ADP ES Files\" & Atmt.FileName

Thanks in advance
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top