none
Two If Statements within one For Statement RRS feed

  • Question

  • This is currently what I have (middle of the script)

        For Each Mail In SubFolder.Items.Restrict("[UnRead] = True")
                
    ' Save any attachments found
            For Each Atmt In Mail.Attachments
                If LCase(Left(Atmt.FileName, 1)) = "a" Then
                FileName = "C:\Documents and Settings\mrlee\Desktop\Test\" & Atmt.FileName
                Atmt.SaveAsFile FileName
                i = i + 1
             
            
                If LCase(Left(Atmt.FileName, 1)) = "i" Then
                FileName = "C:\Documents and Settings\mrlee\Desktop\test1\" & Atmt.FileName
                Atmt.SaveAsFile FileName
                i = i + 1
                End If
               
             Next Atmt
        Next Mail
    Without the second part of the IF statement, this script works properly. Now I want to make it so that it scans for two different prefixes in the attachment. Is that possible?
    Wednesday, August 22, 2012 3:55 PM

Answers

  • Nevermind, figured this out on my own:

           For Each Atmt In Mail.Attachments
                If Left(Atmt.FileName, 1) = "A" Then
                FileName = "C:\Documents and Settings\mrlee\Desktop\Test\" & Atmt.FileName
                Atmt.SaveAsFile FileName
                i = i + 1
               End If
               
             Next Atmt
             
             For Each Atmt In Mail.Attachments
                If Left(Atmt.FileName, 1) = "M" Then
                FileName = "C:\Documents and Settings\mrlee\Desktop\test1\" & Atmt.FileName
                Atmt.SaveAsFile FileName
                i = i + 1
                End If
               
             Next Atmt
        Next Mail

    For those that wanted an answer to this, here you go.
    Wednesday, August 22, 2012 6:03 PM

All replies

  • Nevermind, figured this out on my own:

           For Each Atmt In Mail.Attachments
                If Left(Atmt.FileName, 1) = "A" Then
                FileName = "C:\Documents and Settings\mrlee\Desktop\Test\" & Atmt.FileName
                Atmt.SaveAsFile FileName
                i = i + 1
               End If
               
             Next Atmt
             
             For Each Atmt In Mail.Attachments
                If Left(Atmt.FileName, 1) = "M" Then
                FileName = "C:\Documents and Settings\mrlee\Desktop\test1\" & Atmt.FileName
                Atmt.SaveAsFile FileName
                i = i + 1
                End If
               
             Next Atmt
        Next Mail

    For those that wanted an answer to this, here you go.
    Wednesday, August 22, 2012 6:03 PM
  • Hi Ryan,

    I'm glad to hear that you have solved your issue. Thanks for sharing your experience here. It's very beneficial for other community members who have similar problem to see how your solved your question.

    Best regards,
    Quist


    Quist Zhang [MSFT]
    MSDN Community Support | Feedback to us

    Thursday, August 30, 2012 10:11 AM
    Moderator