rename Files once received on outlook & displaced in a separate File

EL Mehdi

New Member
Joined
Nov 23, 2016
Messages
4
Hello,
This is my first day in the forum so I want to say Hello to everybody :),
I m new in VBA so please support me if I made any mistakes :LOL:
If possible, I m asking help regarding the issue bellow,
I found a small code to copy/past attached files from received emails to a specific file,
The problem is some attached files have a space " " in the end of their names so I want to copy/past them & Correct the name by removing the space,
Now after excexuting my code, the file are attached normally but once a file with " " is detected, no more file are attached,

Unfortunately I can't attache any file as the code is in outlook

Here after my code :

Code:
Public Sub s2aveAttachtoRapportDetailléParEquipeFile(itm As Outlook.MailItem)
Dim objAtt As Outlook.Attachment
Dim saveFolder As String
saveFolder = "C:\Users\LZYRFY\Desktop\Nouveau dossier (2)"
     For Each objAtt In itm.Attachments
          objAtt.SaveAsFile saveFolder & "\" & objAtt.DisplayName
          FileName = CreateObject("Scripting.FileSystemObject").GetBaseName(objAtt)
          File1 = "C:\Users\LZYRFY\Desktop\Nouveau dossier (2)\" & FileName
          MsgBox (File1)
                If Right(FileName, 1) = " " Then
                    FileName = Left(FileName, Len(FileName) - 1)
                    File2 = "C:\Users\LZYRFY\Desktop\Nouveau dossier (2)\" & FileName
                    MsgBox (File2)
                    Name File1 As File2
                End If
          Set objAtt = Nothing
     Next
End Sub

Thank you for your support
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
It s ok I found a solution :cool:
Code:
Public Sub s2aveAttachtoRapportDetailléParEquipeFile(itm As Outlook.MailItem)
Dim objAtt As Outlook.Attachment
Dim saveFolder As String
saveFolder = "C:\Users\LZYRFY\Desktop\Nouveau dossier (2)\"
     For Each objAtt In itm.Attachments
        TheFileName = objAtt.FileName
        If Left(Right(TheFileName, 5), 1) = " " Then
               TheFileName = Left(TheFileName, Len(TheFileName) - 5)
               TheFileName = TheFileName & ".xls"
        End If
            objAtt.SaveAsFile saveFolder & TheFileName
          Set objAtt = Nothing
     Next
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,926
Messages
6,122,306
Members
449,079
Latest member
juggernaut24

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top