• Outlook User
  • New Outlook app
  • Outlook.com
  • Outlook Mac
  • Outlook & iCloud
  • Developer
  • Microsoft 365 Admin
    • Common Problems
    • Microsoft 365
    • Outlook BCM
    • Utilities & Addins

Save Attachments to the Hard Drive

Slipstick Systems

› Developer › Save Attachments to the Hard Drive

Last reviewed on August 13, 2021     423 Comments

A security update disabled the Run a script option in the rules wizard in Outlook 2010 and all newer Outlook versions. See Run-a-Script Rules Missing in Outlook for more information and the registry key to fix restore it.

The following code saves the attachments from selected messages but does not delete the attachments from the message(s). This VBA code is based on the code sample from my Outlook book: Save and Delete Attachments. Use it if you want to save the attachment, add a link to the saved file, and delete the attachment from the message.

Would you prefer to use a utility? See Attachment Management Tools for Outlook

Instructions to add the macro to a toolbar button or ribbon command are at the end of the page.

Save Attachments to the hard drive

Copy and paste the code from this page into your ThisOutlookSession project.

In Outlook, press Alt+F11 to open the VBA editor and expand Microsoft Outlook Objects then double click on ThisOutlookSession to open it in the editing pane and Ctrl+V to paste the code.

To use it you must first create a folder under your My Documents named OLAttachments (the code will not create it for you). Then select one or more messages and run the macro to save the attachments. You'll need to set macro security to warn before enabling macros or sign the macro. You can change the folder name or path where the attachments are saved by editing the code.

Public Sub SaveAttachments()
Dim objOL As Outlook.Application
Dim objMsg As Outlook.MailItem 'Object
Dim objAttachments As Outlook.Attachments
Dim objSelection As Outlook.Selection
Dim i As Long
Dim lngCount As Long
Dim strFile As String
Dim strFolderpath As String
Dim strDeletedFiles As String

    ' Get the path to your My Documents folder
    strFolderpath = CreateObject("WScript.Shell").SpecialFolders(16)
    On Error Resume Next

    ' Instantiate an Outlook Application object.
    Set objOL = Application

    ' Get the collection of selected objects.
    Set objSelection = objOL.ActiveExplorer.Selection

' The attachment folder needs to exist
' You can change this to another folder name of your choice

    ' Set the Attachment folder.
    strFolderpath = strFolderpath & "\OLAttachments\"

    ' Check each selected item for attachments. 
    For Each objMsg In objSelection

    Set objAttachments = objMsg.Attachments
    lngCount = objAttachments.Count
        
    If lngCount > 0 Then
    
    ' Use a count down loop for removing items
    ' from a collection. Otherwise, the loop counter gets
    ' confused and only every other item is removed.
    
    For i = lngCount To 1 Step -1
    
    ' Get the file name.
    strFile = objAttachments.Item(i).FileName
    
    ' Combine with the path to the Temp folder.
    strFile = strFolderpath & strFile
    
    ' Save the attachment as a file.
    objAttachments.Item(i).SaveAsFile strFile
    
    Next i
    End If
    
    Next
    
ExitSub:

Set objAttachments = Nothing
Set objMsg = Nothing
Set objSelection = Nothing
Set objOL = Nothing
End Sub

 

Use an ItemAdd to Save Attachments on Arrival

This macro runs (automatically) on messages as they are added to the Inbox. Put it in ThisOutlookSession.

Option Explicit

Private WithEvents olInboxItems As Items
 
Private Sub Application_Startup()
  Dim objNS As NameSpace
  Set objNS = Application.Session
  ' instantiate objects declared WithEvents
  Set olInboxItems = objNS.GetDefaultFolder(olFolderInbox).Items
  Set objNS = Nothing
End Sub
 
Private Sub olInboxItems_ItemAdd(ByVal Item As Object)
  On Error Resume Next
If Item.Attachments.Count > 0 Then
 
Dim objAttachments As Outlook.Attachments
Dim lngCount As Long
Dim strFile As String
Dim sFileType As String
Dim i as long

Set objAttachments = Item.Attachments
    lngCount = objAttachments.Count
 For i = lngCount To 1 Step -1

' Get the file name.
 strFile = objAttachments.Item(i).FileName

 ' Get the path to your My Documents folder
    strFolderpath = CreateObject("WScript.Shell").SpecialFolders(16)
    strFolderpath = strFolderpath & "\OLAttachments\"

' Combine with the path to the folder.
 strFile = strFolderpath & strFile

' Save the attachment as a file.
 objAttachments.Item(i).SaveAsFile strFile

 Next i
End If

End Sub

 

Use Predefined Folders

This set of macros allows you to define a set of folders to save attachments to. Set the folder path in the small "stub" macros. The folder name is passed to the main macro. Add the macros to the ribbon or Quick Access Toolbar so they are easy to use.

To use: Select one or more messages that have attachments and run the macro.

To create more locations, copy a stub macro, then change the path and macro name. You need to end the file path with a \.

As written, the macro saves all attachments on the selected messages. If you need to filter it by file type, see the examples in other macros on this page.

These macros go in a Module.

Public strFolderpath As String
Public Sub SaveToDiane()
strFolderpath = "c:\diane\"
SaveAttachments
End Sub

Public Sub SaveToProject()
strFolderpath = "C:\project1\"
SaveAttachments
End Sub

Private Sub SaveAttachments()
Dim objOL As Outlook.Application
Dim objMsg As Object
Dim objAttachments As Outlook.Attachments
Dim objSelection As Outlook.Selection
Dim i As Long
Dim lngCount As Long
Dim strFile As String

    On Error Resume Next
    Set objOL = Application

    Set objSelection = objOL.ActiveExplorer.Selection

    ' Check each selected item for attachments.
    For Each objMsg In objSelection

    Set objAttachments = objMsg.Attachments
    lngCount = objAttachments.Count
        
    If lngCount > 0 Then
    
    ' Use a count down loop for removing items
    ' from a collection. Otherwise, the loop counter gets
    ' confused and only every other item is removed.
    
    For i = lngCount To 1 Step -1
    
    ' Get the file name.
    strFile = objAttachments.Item(i).FileName
    
    ' Combine with the path to the folder.
    strFile = strFolderpath & strFile
    
    ' Save the attachment as a file.
    objAttachments.Item(i).SaveAsFile strFile
    
    Next i
    End If
    
    Next
    
ExitSub:

Set objAttachments = Nothing
Set objMsg = Nothing
Set objSelection = Nothing
Set objOL = Nothing
End Sub

 

Run a Script Rule to Save Attachments

This version of the macro works with Rules, saving all attachments in messages that meet the condition of the rule to a folder under the user's documents folder.

To learn more about run a script rules, see Outlook's Rules and Alerts: Run a Script.

Public Sub SaveAttachments(Item As Outlook.MailItem)

If Item.Attachments.Count > 0 Then
 
Dim objAttachments As Outlook.Attachments
Dim lngCount As Long
Dim strFile As String
Dim sFileType As String
Dim i As Long

Set objAttachments = Item.Attachments
    lngCount = objAttachments.Count
 For i = lngCount To 1 Step -1

' Get the file name.
 strFile = objAttachments.Item(i).FileName

 ' Get the path to your My Documents folder
    strfolderpath = CreateObject("WScript.Shell").SpecialFolders(16)
    strfolderpath = strfolderpath & "\Attachments\"

' Combine with the path to the folder.
 strFile = strfolderpath & strFile

' Save the attachment as a file.
 objAttachments.Item(i).SaveAsFile strFile

 Next i
End If

End Sub

 

Add the message date to the filename

If you want to add the message date to the file, you'll need to get the date from the SentOn or ReceivedDate fields then format it as a string before adding it to the file name. It's a total of 4 new lines and one edited line.

First, Dim the two new variables at the top of the macro:

Dim dtDate As Date
Dim sName As String

To format the date and time and add it to the filename in 20130905045911-filename format, you'll add two lines of code after you count the attachments to get the date and format it, then edit the line that creates the filename.
If lngCount > 0 Then

       dtDate = objMsg.SentOn

         sName = Format(dtDate, "yyyymmdd", vbUseSystemDayOfWeek, vbUseSystem) & Format(dtDate, "hhnnss", vbUseSystemDayOfWeek, vbUseSystem) & "-"

   For i = lngCount To 1 Step -1

    ' Get the file name.
       strFile = sName & objAttachments.Item(i).FileName

 

Use the Subject and remove illegal characters

If you use the email subject in the file name, you will need to remove illegal characters that are not supported in Windows file system.

You can do that using the ReplaceCharsForFileName function (below). As written, the illegal characters are replaced with a dash (-) but you can change the word seperator.

Use this to get the subject and remove the illegal characters.

If lngCount > 0 Then

    sSubject = objMsg.Subject
' change the seperator if desired 
    sSubject = ReplaceCharsForFileName sSubject, "-"

   For i = lngCount To 1 Step -1

    ' Get the file name.
       strFile = sSubject & objAttachments.Item(i).FileName

To trim long subjects, use the Left function to get the first characters. This snippet uses the first 25 characters of the subject.
sSubject = left(objMsg.Subject, 25)

To use the date and subject, use this code:

If lngCount > 0 Then

    sSubject = objMsg.Subject
    sSubject = ReplaceCharsForFileName sSubject, "-"
    
    dtDate = objMsg.SentOn
    sName = Format(dtDate, "yyyymmdd", vbUseSystemDayOfWeek, vbUseSystem) & Format(dtDate, "hhnnss", vbUseSystemDayOfWeek, vbUseSystem) & "-"

   For i = lngCount To 1 Step -1
 strFile = sSubject & sName & objAttachments.Item(i).FileName

 

Public Sub ReplaceCharsForFileName(sSubject As String, _
sChr As String _
)
  sSubject = Replace(sSubject, "'", sChr)
  sSubject = Replace(sSubject, "*", sChr)
  sSubject = Replace(sSubject, "/", sChr)
  sSubject = Replace(sSubject, "\", sChr)
  sSubject = Replace(sSubject, ":", sChr)
  sSubject = Replace(sSubject, "?", sChr)
  sSubject = Replace(sSubject, Chr(34), sChr)
  sSubject = Replace(sSubject, "<", sChr)
  sSubject = Replace(sSubject, ">", sChr)
  sSubject = Replace(sSubject, "|", sChr)
End Sub

 

Don't save images in signatures

This macro saves all attachments, including images embedded in signatures (they are attachments after all). To avoid saving signature images, you have two options: don't save image files, or don't save smaller files. You could even do both and save only larger images files.

Replace the code between For i = lngCount To 1 Step -1 / Next i lines with the following to filter out files smaller than 5KB. This should catch most signature images (and many text files).

If the attachments you need to save are always over 5 KB, you can increase the file size. (For reference, a blank Word document is over 10KB.)

    For i = lngCount To 1 Step -1
       If objAttachments.Item(i).Size > 5200 Then

    ' Get the file name.
    strFile = objAttachments.Item(i).filename
     
    ' Combine with the path to the Temp folder.
    strFile = strFolderpath & strFile
     
    ' Save the attachment as a file.
    objAttachments.Item(i).SaveAsFile strFile
     End If
     
    Next i

 

Save by File type

If you want to skip or save only a specific file type, use If LCase(Right(strFile, 4)) <> ".ext" format, where .ext is the extension. Add it after the first line strFile = line (and don't forget to add the End if before the Next i). You can use it to exclude a file type or use an equal (=) sign to save only a specific file type. (For 4-character extensions, use only the characters, don't include the dot.)

To work with a longer list of file types, use a Select Case statement. In this example, we're looking for image attachments, and if less than approx 5KB, we skip them. Larger image attachments will be saved.

 For i = lngCount To 1 Step -1
     
    ' Get the file name.
    strFile = objAttachments.Item(i).filename
     
' This code looks at the last 4 characters in a filename
      sFileType = LCase$(Right$(strFile, 4))
 
      Select Case sFileType
 ' Add additional file types below
       Case ".jpg", ".png", ".gif"
        If objAttachments.Item(i).Size < 5200 Then
     GoTo nexti
        End If
      End Select
   
    ' Combine with the path to the Temp folder.
    strFile = strFolderpath & strFile
     
    ' Save the attachment as a file.
    objAttachments.Item(i).SaveAsFile strFile
    
nexti:
    Next i

 

Increment duplicate file names

This version of the macro check to see if the file exists, it so, it adds a number to the file name.
increment filename

Public Sub SaveAttachments()
Dim objOL As Outlook.Application
Dim objMsg As Outlook.MailItem 'Object
Dim objAttachments As Outlook.Attachments
Dim objSelection As Outlook.Selection
Dim i As Long
Dim lngCount As Long
Dim strFile As String
Dim strFolderpath As String
Dim strDeletedFiles As String

    ' Get the path to your My Documents folder
    strFolderpath = CreateObject("WScript.Shell").SpecialFolders(16)
    On Error Resume Next

    ' Instantiate an Outlook Application object.
    Set objOL = Application

    ' Get the collection of selected objects.
    Set objSelection = objOL.ActiveExplorer.Selection

' The attachment folder needs to exist
' You can change this to another folder name of your choice

    ' Set the Attachment folder.
    strFolderpath = strFolderpath & "\"

    ' Check each selected item for attachments.
    For Each objMsg In objSelection

    Set objAttachments = objMsg.Attachments
    lngCount = objAttachments.Count
        
    If lngCount > 0 Then
    
    ' Use a count down loop for removing items
    ' from a collection. Otherwise, the loop counter gets
    ' confused and only every other item is removed.
    
For i = lngCount To 1 Step -1
    
 ' Get the file name.
    strFile = objAttachments.Item(i).Filename
    
    lCount = InStrRev(strFile, ".") - 1
    pre = Left(strFile, lCount)
    ext = Right(strFile, Len(strFile) - lCount)
 
    ' Combine with the path to make the final path
    strFile = strFolderpath & pre & ext
    
    'check for existing
    Dim nnumber As String
    nnumber = 0
    
    Do
    FileExists = Dir(strFile)
    
    If FileExists = "" Then
    Exit Do
    Else
    
    nnumber = nnumber + 1
    strFile = strFolderpath & pre & "(" & nnumber & ")" & ext
    
    End If
    Loop

Debug.Print strFile

objAttachments.Item(i).SaveAsFile strFile
    
    Next i
    End If
    
    Next
    
ExitSub:

Set objAttachments = Nothing
Set objMsg = Nothing
Set objSelection = Nothing
Set objOL = Nothing
End Sub

 

Add a number to each attachment

This macro merges the first macro on this page with the macro at Write the last used value to the registry sample to add a number to each saved attachment, incrementing as attachments are saved. Because the last used value is in the registry, the count will persist because restarts.

Get the complete macro, ready to use: AttachmentIndex

 ' HKEY_CURRENT_USER\Software\VB and VBA Program Settings\Outlook\Index
    sAppName = "Outlook"
    sSection = "Index"
    sKey = "Last Index Number"
 ' The default starting number.
     iDefault = 101 ' adjust as needed
  
 ' Get stored registry value, if any.
     lRegValue = GetSetting(sAppName, sSection, sKey, iDefault)
  
 ' If the result is 0, set to default value.
     If lRegValue = 0 Then lRegValue = iDefault
 
' Put the save attachment code here 
    strFolderpath = CreateObject("WScript.Shell").SpecialFolders(16)
    On Error Resume Next
 
    Set objOL = Application
    Set objSelection = objOL.ActiveExplorer.Selection
    strFolderpath = strFolderpath & "\OLAttachments\"
 
    For Each objMsg In objSelection
    Set objAttachments = objMsg.Attachments
    lngCount = objAttachments.Count
         
    If lngCount > 0 Then
    For i = lngCount To 1 Step -1
    
 ' Get the file name.
    strFile = objAttachments.Item(i).fileName
    
    lcount = InStrRev(strFile, ".") - 1
    pre = Left(strFile, lcount)
    ext = Right(strFile, Len(strFile) - lcount)
 
    ' Combine with the path to make the final path
    strFile = strFolderpath & pre & "_" & lRegValue & ext
  
    strFile = strFolderpath & strFile
    objAttachments.Item(i).SaveAsFile strFile

' add 1 to the index  
    lRegValue = lRegValue + 1
        Err.Clear
    Next
    
   ' update the registry at the end
     SaveSetting sAppName, sSection, sKey, lRegValue

 

Save Attachments in Subfolders

To save the attachments in subfolders, you need to use the File Scripting Object to create the folder if it does not exist.

A complete, ready-to-use sample macro is here.

For Each objMsg In objSelection
 
  ' Set the Attachment folder.
    strFolder = strFolderpath & "\OLAttachments\"  
    Set objAttachments = objMsg.Attachments
' put it together with the sender name  
 strFolder = strFolder & objMsg.SenderName & "\"
    
 ' if the sender's folder doesn't exist, create it
 If Not FSO.FolderExists(strFolder) Then
 FSO.CreateFolder (strFolder)
 End If
 
    lngCount = objAttachments.Count        
    If lngCount > 0 Then
      For i = lngCount To 1 Step -1
    strFile = objAttachments.Item(i).FileName
    strFile = strFolder & strFile
    objAttachments.Item(i).SaveAsFile strFile

 

Use Macro with Different Folders

This version of the macro save the attachments on the selected message to a subfolder. By using a "stub macro" to set the name of the subfolder, you can don't need ot repeat the long macro multiple times to use it with different pre-defined folders.

In this example, I'm either saving the attachment to From Bob or From Jim folder in my Documents folder.
C:\Users\username\Documents\From Bob\
C:\Users\username\Documents\From Jim\

Create buttons on the ribbon for the stub macros. Select the message then click the appropriate button.

Dim strFolder As String
Public Sub SaveToFolderBob()
    strFolder = "From Bob"
    SaveAttachments
End Sub

Public Sub SaveToFolderJim()
    strFolder = "From Jim"
    SaveAttachments
End Sub

Private Sub SaveAttachments()
Dim objOL As Outlook.Application
Dim objMsg As Outlook.MailItem 'Object
Dim objAttachments As Outlook.Attachments
Dim objSelection As Outlook.Selection
Dim i As Long
Dim lngCount As Long
Dim strFile As String
Dim strFolderpath As String
Dim strDeletedFiles As String

    ' Get the path to your My Documents folder
    strFolderpath = CreateObject("WScript.Shell").SpecialFolders(16)
    Debug.Print strFolderpath
    On Error Resume Next

' The attachment folder needs to exist
' You can change this to another folder name of your choice

    ' Set the Attachment folder.
    strFolderpath = strFolderpath & "\" & strFolder & "\"
    Debug.Print strFolderpath

    Set objOL = Outlook.Application
    Set objMsg = objOL.ActiveExplorer.Selection.Item(1)

    Set objAttachments = objMsg.Attachments
    lngCount = objAttachments.Count
        
    If lngCount > 0 Then
    
    ' Use a count down loop for removing items
    ' from a collection. Otherwise, the loop counter gets
    ' confused and only every other item is removed.
    
    For i = lngCount To 1 Step -1
    
    ' Get the file name.
    strFile = objAttachments.Item(i).FileName
    
    ' Combine with the path to the Temp folder.
    strFile = strFolderpath & strFile
    
    ' Save the attachment as a file.
    objAttachments.Item(i).SaveAsFile strFile
    
    Next i
    End If
        
ExitSub:

Set objAttachments = Nothing
Set objMsg = Nothing
Set objSelection = Nothing
Set objOL = Nothing
End Sub

Assign the macro to a button

In Outlook 2007 and older, you can create a toolbar button to run the macro. In Outlook 2010, you'll need to customize the ribbon.

More information is at Customize the Outlook Toolbar, Ribbon or QAT and at Customizing the Quick Access Toolbar (QAT).

Run the macro using a ribbon or QAT shortcut

Step 1: To create a button to run a macro in Outlook 2010, go to File, Options, and choose Customize Ribbon. (If you want a button on the QAT, choose Quick Access Toolbar instead.)
customize the ribbon to add a macro button
Step 2: Choose Macro from the Choose Commands From menu and select the macro you want to add to the ribbon or QAT.

Step 3: Select the Group you want to add the macro to. If it doesn't exist yet, use the New Group buttons to create the group.

Step 4: Use the Rename button to give the macro a friendly name and change the icon. You are limited to the icons in the dialog (unless you want to program a ribbon command).

Run the macro from a toolbar button

To create a toolbar button for it, go to View, Toolbar, Customize, Commands tab. In the Categories pane, type M to jump to Macros. On the Commands side, drag the macro you created to the toolbar. Right click on the button to rename it and assign a new icon.

customize toolbar dialog

Save Attachments to the Hard Drive was last modified: August 13th, 2021 by Diane Poremsky

Related Posts:

  • Save Messages and Attachments to a New Folder
  • Save and Delete Attachments from Outlook messages
  • Save and Open an Attachment using VBA
  • Browseforfolder_2
    How to use Windows File Paths in a Macro

About Diane Poremsky

A Microsoft Outlook Most Valuable Professional (MVP) since 1999, Diane is the author of several books, including Outlook 2013 Absolute Beginners Book. She also created video training CDs and online training classes for Microsoft Outlook. You can find her helping people online in Outlook Forums as well as in the Microsoft Answers and TechNet forums.

Subscribe
Notify of
423 Comments
newest
oldest most voted
Inline Feedbacks
View all comments

Hunter Evans
January 22, 2025 3:05 pm

I am using the code below to try to save attachments in a group of emails to a specific folder based on the subject. It also includes a way to add a number to the front on the emails that have the exact same subject. The code instead saves all attachments to the first folder listed and doesn't move them based on subject. Is there a way to do this? Public Sub SaveAttachments() Dim objOL As Outlook.Application Dim objMsg As Outlook.MailItem 'Object Dim objAttachments As Outlook.Attachments Dim objSelection As Outlook.Selection Dim i As Long Dim lngCount As Long Dim strFile As String Dim strFolderpath As String Dim strDeletedFiles As String Dim sSubject As String On Error Resume Next ' Get the path to your My Documents folder If InStr(1, objMsg.Subject, "Plant Production Schedule Report") Then strFolderpath = "C:\downloads\shipment schedule\Morning\Test2\Prod Sch\" Else: strFolderpath = "C:\downloads\shipment schedule\Morning\Test2" End If ' Instantiate an Outlook Application object. Set objOL = Application ' Get the collection of selected objects. Set objSelection = objOL.ActiveExplorer.Selection ' Set the Attachment folder. strFolderpath = strFolderpath ' Check each selected item for attachments. For Each objMsg In objSelection Set objAttachments = objMsg.Attachments strFolder = strFolder lngCount = objAttachments.Count If lngCount… Read more »

0
0
Reply
Diane Poremsky
Author
Reply to  Hunter Evans
January 22, 2025 3:22 pm

The folder path need to be set just prior to the save -

For Each objMsg In objSelection
' set path here if all attachments on the message go into the same folder.
Set objAttachments = objMsg.Attachments

This should work: (but I did not test it :))

For Each objMsg In objSelection
If InStr(1, objMsg.Subject, "Plant Production Schedule Report") Then
strFolderpath = "C:\downloads\shipment schedule\Morning\Test2\Prod Sch\"
Else: strFolderpath = "C:\downloads\shipment schedule\Morning\Test2"
End If
Set objAttachments = objMsg.Attachments

0
0
Reply
Hunter Evans
Reply to  Diane Poremsky
January 23, 2025 9:57 am

Thanks. This worked perfectly!!!!

0
0
Reply
Hunter Evans
Reply to  Diane Poremsky
February 11, 2025 3:54 pm

Not sure my reply came through earlier. I am using the attached VBA that you previously assisted me with. It is working great except I need the new file names to include the attachments file extension. Right now, an email with the subject Production Schedule and an attachment that is 217080.txt saves as Production Schedule with no file type. I need it to save as Production Schedule.txt. The files in question are both .txt and .csv. Thanks.

Email VBA
0
0
Reply
Diane Poremsky
Author
Reply to  Hunter Evans
February 11, 2025 4:15 pm

I'll take a look at the code and see what needs to be changed.

0
0
Reply
Hunter Evans
Reply to  Diane Poremsky
February 13, 2025 9:42 am

Sorry to be a pest, but wondered if you were able to look at my VBA to see how it could be adjusted to achieve what I am looking for. Thanks.

0
0
Reply
Diane Poremsky
Author
Reply to  Hunter Evans
February 14, 2025 1:57 am

Not a problem - it looks like you are not getting the extension -

strFile = sSubject & sExtension

You need to get the extension from the attachment name like this -

' Get the file name.
strFile = objAttachments.Item(i).Filename
lCount = InStrRev(strFile, ".") - 1
sExtension= Right(strFile, Len(strFile) - lCount)

if the extensions will all be 4 characters (.docx, .xlsx), you can use this

sExtension= Right(objAttachments.Item(i).Filename, 5)

0
0
Reply
Ryan
July 9, 2024 6:21 pm

My VBA Script is not working. I've altered your script to download an .xlsx attachment and rename it as a standardized .xlsx filename. But it doesn't work. I'm wondering if it won't save and replace the current file. Attached is the script. Any help would be appreciated.

Public Sub SaveExcelEmailAttachment
0
0
Reply
Diane Poremsky
Author
Reply to  Ryan
January 23, 2025 10:37 am

The first step is to uncomment this line so you can see if the path is correct. (Remove the ' from the beginning.)
' Debug.Print strFolderpath & strDestName

0
0
Reply
RAE
March 23, 2024 5:39 am

WOW! Thanks Diane. Greetings from New Zealand. You saved me from having to click on 50 different email attachments. My fingers thank you.

0
0
Reply
Anders
January 4, 2024 10:03 am

Hi Diane
Does "Increment duplicate file names" work with Outlook 365?
I wanted my own file path so I changed

' Get the path to your My Documents folder
    strFolderpath = CreateObject("WScript.Shell").SpecialFolders(16)
    On Error Resume Next
to

' Get the path to your My Documents folder
    strFolderpath = "C:\my path"
    On Error Resume Next
is this correct?

Thanks!

Edit: I noticed when I read my post that I've missed the last "\" in my path.

Last edited 1 year ago by Anders
0
0
Reply
Diane Poremsky
Author
Reply to  Anders
January 9, 2024 8:29 am

The desktop Outlook that is installed with Microsoft 365 Office subscription software, yes it works with it. Outlook on the web, no.

0
0
Reply
Paul Campbell
November 20, 2023 4:20 pm

Jesus God in Heaven, Thank you Diane Poremsky

You've coded your way into my heart.

A blessing on your head. Mazeltov.

Forever grateful,

Amen.

0
0
Reply
Bogue
October 4, 2023 2:59 pm

Thanks Diane! This has been extremely helpful. I am looking at saving excel files to a local drive; however, the excel files have their first 3 rows completely blank. Is there anyway to delete those rows upon download?

Thanks in advance!

0
0
Reply
Diane Poremsky
Author
Reply to  Bogue
October 16, 2023 9:11 am

You would need to use an Excel macro to do that. It could be converted to an Outlook macro that opens the file and deletes the empty rows. I don't have a macro that does it though.

0
0
Reply
Sophie
August 15, 2023 1:24 pm

Hi Diane! Thank you for your codes, they'll be saving me a lot of time. I'm using the "Use the Subject and remove illegal characters" one but the files are getting renamed to the subject + the original filename. Is there any way to make it so that it renames the files to the subject only? I'm new to VBA and I didn't manage to modify it myself.

0
0
Reply
Grace
May 18, 2023 7:16 am

Thanks Diane!

0
0
Reply

Visit Slipstick Forums.
What's New at Slipstick.com

Latest EMO: Vol. 30 Issue 36

Subscribe to Exchange Messaging Outlook






Support Services

Do you need help setting up Outlook, moving your email to a new computer, migrating or configuring Office 365, or just need some one-on-one assistance?

Our Sponsors

CompanionLink
ReliefJet
  • Popular
  • Latest
  • Week Month All
  • Use Classic Outlook, not New Outlook
  • Mail Templates in Outlook for Windows (and Web)
  • How to Remove the Primary Account from Outlook
  • Reset the New Outlook Profile
  • Disable "Always ask before opening" Dialog
  • Adjusting Outlook's Zoom Setting in Email
  • This operation has been cancelled due to restrictions
  • How to Hide or Delete Outlook's Default Folders
  • Remove a password from an Outlook *.pst File
  • Removing Suggested Accounts in New Outlook
  • Opt out of Microsoft 365 Companion Apps
  • Mail Templates in Outlook for Windows (and Web)
  • Urban legend: Microsoft Deletes Old Outlook.com Messages
  • Buttons in the New Message Notifications
  • Move Deleted Items to Another Folder Automatically
  • Open Outlook Templates using PowerShell
  • Count and List Folders in Classic Outlook
  • Google Workspace and Outlook with POP Mail
  • Import EML Files into New Outlook
  • Opening PST files in New Outlook
Ajax spinner

Recent Bugs List

Microsoft keeps a running list of issues affecting recently released updates at Fixes or workarounds for recent issues in classic Outlook (Windows).

For new Outlook for Windows: Fixes or workarounds for recent issues in new Outlook for Windows .

Outlook for Mac Recent issues: Fixes or workarounds for recent issues in Outlook for Mac

Outlook.com Recent issues: Fixes or workarounds for recent issues on Outlook.com

Office Update History

Update history for supported Office versions is at Update history for Office

Outlook Suggestions and Feedback

Outlook Feedback covers Outlook as an email client, including Outlook Android, iOS, Mac, and Windows clients, as well as the browser extension (PWA) and Outlook on the web.

Outlook (new) Feedback. Use this for feedback and suggestions for Outlook (new).

Use Outlook.com Feedback for suggestions or feedback about Outlook.com accounts.

Other Microsoft 365 applications and services




New Outlook Articles

Opt out of Microsoft 365 Companion Apps

Mail Templates in Outlook for Windows (and Web)

Urban legend: Microsoft Deletes Old Outlook.com Messages

Buttons in the New Message Notifications

Move Deleted Items to Another Folder Automatically

Open Outlook Templates using PowerShell

Count and List Folders in Classic Outlook

Google Workspace and Outlook with POP Mail

Import EML Files into New Outlook

Opening PST files in New Outlook

Newest Code Samples

Open Outlook Templates using PowerShell

Count and List Folders in Classic Outlook

Insert Word Document into Email using VBA

Warn Before Deleting a Contact

Use PowerShell to Delete Attachments

Remove RE:, FWD:, and Other Prefixes from Subject Line

Change the Mailing Address Using PowerShell

Categorize @Mentioned Messages

Send an Email When You Open Outlook

Delete Old Calendar Events using VBA

VBA Basics

How to use the VBA Editor

Work with open item or selected item

Working with All Items in a Folder or Selected Items

VBA and non-default Outlook Folders

Backup and save your Outlook VBA macros

Get text using Left, Right, Mid, Len, InStr

Using Arrays in Outlook macros

Use RegEx to extract message text

Paste clipboard contents

Windows Folder Picker

Custom Forms

Designing Microsoft Outlook Forms

Set a custom form as default

Developer Resources

Developer Resources

Developer Tools

VBOffice.net samples

SlovakTech.com

Outlook MVP David Lee

Repair PST

Convert an OST to PST

Repair damaged PST file

Repair large PST File

Remove password from PST

Merge Two Data Files

Sync & Share Outlook Data

  • Share Calendar & Contacts
  • Synchronize two computers
  • Sync Calendar and Contacts Using Outlook.com
  • Sync Outlook & Android Devices
  • Sync Google Calendar with Outlook
  • Access Folders in Other Users Mailboxes

Diane Poremsky [Outlook MVP]

Make a donation

Mail Tools

Sending and Retrieval Tools

Mass Mail Tools

Compose Tools

Duplicate Remover Tools

Mail Tools for Outlook

Online Services

Calendar Tools

Schedule Management

Calendar Printing Tools

Calendar Reminder Tools

Calendar Dates & Data

Time and Billing Tools

Meeting Productivity Tools

Duplicate Remover Tools

Productivity

Productivity Tools

Automatic Message Processing Tools

Special Function Automatic Processing Tools

Housekeeping and Message Management

Task Tools

Project and Business Management Tools

Choosing the Folder to Save a Sent Message In

Run Rules on messages after reading

Help & Suggestions

Submit Outlook Feature Requests

Slipstick Support Services

Buy Microsoft 365 Office Software and Services

Visit Slipstick Forums.

What's New at Slipstick.com

Home | Outlook User | Exchange Administrator | Office 365 | Outlook.com | Outlook Developer
Outlook for Mac | Common Problems | Utilities & Addins | Tutorials
Outlook & iCloud Issues | Outlook Apps
EMO Archives | About Slipstick | Slipstick Forums
Submit New or Updated Outlook and Exchange Server Utilities

Send comments using our Feedback page
Copyright © 2025 Slipstick Systems. All rights reserved.
Slipstick Systems is not affiliated with Microsoft Corporation.

:wpds_smile::wpds_grin::wpds_wink::wpds_mrgreen::wpds_neutral::wpds_twisted::wpds_arrow::wpds_shock::wpds_unamused::wpds_cool::wpds_evil::wpds_oops::wpds_razz::wpds_roll::wpds_cry::wpds_eek::wpds_lol::wpds_mad::wpds_sad::wpds_exclamation::wpds_question::wpds_idea::wpds_hmm::wpds_beg::wpds_whew::wpds_chuckle::wpds_silly::wpds_envy::wpds_shutmouth:
wpDiscuz

Sign up for Exchange Messaging Outlook

Our weekly Outlook & Exchange newsletter (bi-weekly during the summer)






Please note: If you subscribed to Exchange Messaging Outlook before August 2019, please re-subscribe.

Never see this message again.

You are going to send email to

Move Comment