To download only excels from a specific folder outlook



" to downlad only excels from a specific foloder of inbox to a folder which we give"

Sub TodownloadAttachments()

'delcare variables
    Dim ns As NameSpace
    Dim inbox As MAPIFolder
    Dim item As Object
    Dim Atmt As Attachment
    Dim filename As String
    Dim SubFolder As MAPIFolder
    Dim i As Integer
    Dim fol As String
'set varilables
fol = InputBox("enter folder name")


Set ns = GetNamespace("MAPI")
 Set inbox = ns.GetDefaultFolder(olFolderInbox)
Set SubFolder = inbox.Folders(fol)


 i = 0

 For Each item In SubFolder.Items
    For Each Atmt In item.Attachments
       filename = "\\d\a\Desktop\s\" & Atmt.filename
       Atmt.SaveAsFile filename
       i = i + 1
    Next Atmt
 Next item

 
End Sub


-------------------------------------------------------------
Option Explicit
Const folderpath = "\\d\e\Desktop\Aas"
Sub downloadallxls()
On Error Resume Next
Dim ns As NameSpace
Set ns = GetNamespace("MAPI")
Dim inbox As MAPIFolder
Set inbox = ns.GetDefaultFolder(olFolderInbox)
Dim serchfolder As String

serchfolder = InputBox("what folder mails you wanted to store index")
Dim subfloder As MAPIFolder

Dim item As Object
Dim attach As Attachment
Dim filename As String
Dim i As Integer

If serchfolder <> "Inbox" Then
Set SubFolder = inbox.Folders(serchfolder)
i = 0
If SubFolder.Items.Count = 0 Then
    MsgBox " There are No Msgs in The Floder", vbInformation, "Nothing is Found"
Exit Sub
For Each itemm In SubFolder.Items
For Each attach In item.Attachment
attach.SaveAsFile (folderpath & attach.filename)
i = i + 1
Next attach
Next item
End If

End Sub

Comments

Popular posts from this blog

number format

send Mail by outlook from excel sheet

Find and copy the data