cavanoos
Altın Üye
- Katılım
- 17 Aralık 2008
- Mesajlar
- 781
- Excel Vers. ve Dili
- Microsoft 365
Merhaba arkadaşlar;
Gelen kutusundaki maillerde içinde txt uzantılı ekli dosyaları bilgisayarıma indirmek için kullandığım bir makro kodu var.Gayet güzelde çalışıyor.Ancak ekli dosyaların ismi aynı ise bir tanesini alıyor.Diğerini almıyor.
Örnek verirsek 10 adet txt uzantılı dosyanın ismide Garanti ise bir tanesini alıyor.Diğerlerini almıyor.Bu mailleri klasöre kaydederken garanti1 , garanti2 ,garanti3...deme gibi bir şansımız var mıdır ?
Kullandığım kod aşağıdadır.Yardım edebilir misiniz ?
Public Sub SaveAllAttachments()
Dim App As New Outlook.Application
Dim Exp As Outlook.Explorer
Dim Sel As Outlook.Items
Dim AttachmentCnt As Integer
Dim AttTotal As Integer
Dim MsgTotal As Integer
Dim outputDir As String
Dim outputFile As String
Dim fileExists As Boolean
Dim cnt As Integer
Dim fso As FileSystemObject
Set Exp = App.ActiveExplorer
Set Sel = Exp.CurrentFolder.Items
Set fso = New FileSystemObject
outputDir = "D:\UGUR\" 'Klasör Adresi
For cnt = 1 To Sel.Count
If Sel.Item(cnt).Attachments.Count > 0 Then
MsgTotal = MsgTotal + 1
For AttachmentCnt = 1 To Sel.Item(cnt).Attachments.Count
Dim att As Attachment
Set att = Sel.Item(cnt).Attachments.Item(AttachmentCnt)
outputFile = UCase(att.FileName)
If Right(outputFile, 3) = "RAR" Then
fileExists = fso.fileExists(outputDir + outputFile)
Do While fileExists = True
outputFile = InputBox("The file " + outputFile _
+ " already exists in the destination directory of " _
+ outputDir + ". Please enter a new name, or hit cancel to skip this one file.", "File Exists", outputFile)
If outputFile = "" Then
Exit Do
End If
fileExists = fso.fileExists(outputDir + outputFile)
Loop
If fileExists = False Then
att.SaveAsFile (outputDir + outputFile)
AttTotal = AttTotal + 1
End If
End If
Next
End If
Next
Set Sel = Nothing
Set Exp = Nothing
Set App = Nothing
Set fso = Nothing
Dim doneMsg As String
doneMsg = "Completed saving " + Format$(AttTotal, "#,0") + " attachments in " + Format$(MsgTotal, "#,0") + " Messages."
MsgBox doneMsg, vbOKOnly, "Save All Attachments"
Exit Sub
ErrorHandler:
Dim errMsg As String
errMsg = "An error has occurred. Error " + Err.Number + " " + Err.Description
Dim errResult As VbMsgBoxResult
errResult = MsgBox(errMsg, vbAbortRetryIgnore, "Error in Save Attachments")
Select Case errResult
Case vbAbort
Exit Sub
Case vbRetry
Resume
Case vbIgnore
Resume Next
End Select
End Sub
Gelen kutusundaki maillerde içinde txt uzantılı ekli dosyaları bilgisayarıma indirmek için kullandığım bir makro kodu var.Gayet güzelde çalışıyor.Ancak ekli dosyaların ismi aynı ise bir tanesini alıyor.Diğerini almıyor.
Örnek verirsek 10 adet txt uzantılı dosyanın ismide Garanti ise bir tanesini alıyor.Diğerlerini almıyor.Bu mailleri klasöre kaydederken garanti1 , garanti2 ,garanti3...deme gibi bir şansımız var mıdır ?
Kullandığım kod aşağıdadır.Yardım edebilir misiniz ?
Public Sub SaveAllAttachments()
Dim App As New Outlook.Application
Dim Exp As Outlook.Explorer
Dim Sel As Outlook.Items
Dim AttachmentCnt As Integer
Dim AttTotal As Integer
Dim MsgTotal As Integer
Dim outputDir As String
Dim outputFile As String
Dim fileExists As Boolean
Dim cnt As Integer
Dim fso As FileSystemObject
Set Exp = App.ActiveExplorer
Set Sel = Exp.CurrentFolder.Items
Set fso = New FileSystemObject
outputDir = "D:\UGUR\" 'Klasör Adresi
For cnt = 1 To Sel.Count
If Sel.Item(cnt).Attachments.Count > 0 Then
MsgTotal = MsgTotal + 1
For AttachmentCnt = 1 To Sel.Item(cnt).Attachments.Count
Dim att As Attachment
Set att = Sel.Item(cnt).Attachments.Item(AttachmentCnt)
outputFile = UCase(att.FileName)
If Right(outputFile, 3) = "RAR" Then
fileExists = fso.fileExists(outputDir + outputFile)
Do While fileExists = True
outputFile = InputBox("The file " + outputFile _
+ " already exists in the destination directory of " _
+ outputDir + ". Please enter a new name, or hit cancel to skip this one file.", "File Exists", outputFile)
If outputFile = "" Then
Exit Do
End If
fileExists = fso.fileExists(outputDir + outputFile)
Loop
If fileExists = False Then
att.SaveAsFile (outputDir + outputFile)
AttTotal = AttTotal + 1
End If
End If
Next
End If
Next
Set Sel = Nothing
Set Exp = Nothing
Set App = Nothing
Set fso = Nothing
Dim doneMsg As String
doneMsg = "Completed saving " + Format$(AttTotal, "#,0") + " attachments in " + Format$(MsgTotal, "#,0") + " Messages."
MsgBox doneMsg, vbOKOnly, "Save All Attachments"
Exit Sub
ErrorHandler:
Dim errMsg As String
errMsg = "An error has occurred. Error " + Err.Number + " " + Err.Description
Dim errResult As VbMsgBoxResult
errResult = MsgBox(errMsg, vbAbortRetryIgnore, "Error in Save Attachments")
Select Case errResult
Case vbAbort
Exit Sub
Case vbRetry
Resume
Case vbIgnore
Resume Next
End Select
End Sub
