outlook ile gelen kutusunda tasnif ettiğim klasörlerin birinden ekleri almak istiyorum

tahsinanarat

Altın Üye
Katılım
14 Mart 2005
Mesajlar
2,164
Excel Vers. ve Dili
Ofis 2019 Türkçe
Altın Üyelik Bitiş Tarihi
27-05-2028
Kod:
Sub AttachmentDownload()

Dim objNS As Outlook.Namespace: Set objNS = GetNamespace("MAPI")
Dim olFolder As Outlook.MAPIFolder

Dim item As Object
Dim at As Outlook.Attachment
Dim sname As String
Dim stdir As String
Dim ws As Worksheet
Dim emailcnt As Variant

Set olFolder = objNS.GetDefaultFolder(olFolderInbox)


ThisWorkbook.Activate
Set ws = Sayfa1

un = "Dear " & Environ("UserName")

emailcnt = InputBox("Enter a Number for Email Count", un, 1000)
If IsNumeric(emailcnt) = False Then
    mb = MsgBox("Default Value of 1000 Selected", vbExclamation, un)
    emailcnt = 1000
    emailcnt = emailcnt * 1
End If

With Application
    .DisplayAlerts = False
    .ScreenUpdating = False
End With

With ws
    .Range("A1").Value = "Email Subject"
    .Range("B1").Value = "Attachment Count"
End With

y = ws.Cells(Rows.Count, 1).End(xlUp).Row
y = y + 1
stdir = Environ("USERPROFILE") & "\" & "Desktop" & "\" & "Attachments Folder"

If Dir(stdir, vbDirectory) = vbNullString Then
    MkDir (stdir)
End If

For Each item In olFolder.Items
    If TypeOf item Is Outlook.MailItem Then
        Dim oMail As Outlook.MailItem: Set oMail = item
      
        With ws
            .Cells(y, 1) = oMail.Subject
            .Cells(y, 2) = oMail.Attachments.Count
        End With
      
        On Error Resume Next
      
        For Each at In oMail.Attachments
            If VBA.InStr(at.Filename, ".pdf") > 0 Then
                at.SaveAsFile stdir & "\" & at.Filename
            End If
        Next
        y = y + 1
        If y = emailcnt Then
            mb1 = MsgBox("Searching First " & emailcnt & " Email Finished", vbInformation, un)
            GoTo sonlandır:
        End If
    End If
Next

sonlandır:

With ws
    .Range("A1:B1").EntireColumn.AutoFit
End With

With Application
    .DisplayAlerts = True
    .ScreenUpdating = True
End With

End Sub


Yukarıdaki Sn. mcanbulat'a ait kod ile outlook dan gelen klasördeki pdf dosyalarını alabiliyorum.
Ben gelen klasördeki değilde Belirttiğim klasör içindekileri almak istersem;
Set olFolder = objNS.GetDefaultFolder(olFolderInbox)
örneğin deneme adlı klasöründeki dosyalarımı almak istersem, kodda nasıl bir değişiklik yapmalayım.
Teşekkürler.
 
Üst