Consulting

Results 1 to 2 of 2

Thread: Change file name and keep extension

  1. #1

    Change file name and keep extension

    I'm working with Outlook and used a combination of a Rule and VBA to automatically save files of a specific name to a folder. When I try to enter my own file name, it corrupts the file. It won't let me edit the name. I'm using this:

    For Each objAtt In itm.Attachments        
                  If InStr(objAtt.DisplayName, ".xlsx") Then
                        objAtt.SaveAsFile saveFolder & "\" & dateFormat & " - " & objAtt.DisplayName
                  End If
                        Set objAtt = Nothing
              Next
    This adds the date before the current file name and saves it to a specified location. I'm looking to edit my code to save files, keep the extension (to avoid corrupting the file), and change the name of the file. What should I use to call the current extension of the file?

    One other issue: I currently have it set to only save .xlsx files because the signature contains a picture that automatically saves. Is there a way to not download the .jpg or .png file, rather than only download the .xlsx?

  2. #2
    The following should work

    If Not objAtt.fileName Like "image*.*" Then
        strFname = objAtt.fileName
        strExt = Right(strFname, Len(strFname) - InStrRev(strFname, Chr(46)) + 1)
        strFname = "My New Filename" & strExt
        objAtt.SaveAsFile strSaveFldr & strFname
    End If
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •