VBA to Download Attachment

vba code to save specific email attachments from outlook folder
outlook vba save attachment with specific subject
outlook vba save attachment to network folder
vba code to save email attachments from outlook folder
how to automatically download/save attachments from outlook to a certain folder
outlook vba save attachment from specific sender
excel vba code to save email attachments from outlook folder
vba outlook attachment

I am wanting to download attachments from email going to a specific folder, I wrote a VB Script and set a rule for emails going in that folder.

It all seems to work just fine, but when it downloads the attachment, it saves it as just a "File" Type, not xlsx. And if I open it, it is all random nonsense. A sample of the file contents:

¬Ia‹YéÎÞé}yý¶ª;ßëÖëê—zõ^CBš¥Î¹]U]u·ÿ~ÿzoÝGôÉñÉñ!8„w1uÒä

I can't figure out what I'm doing wrong, and I've tried all the help I could find online.

My VB script below.

Public Sub saveAttachtoDisk(itm As Outlook.MailItem)

Dim objAtt As Outlook.Attachment
Dim saveFolder As String
Dim strFileType As String
Dim DtString As String
Dim SName As String
Dim File_Name As String
Dim Full_Path As String

saveFolder = "\\path\path\path\path\Path\"

strFileType = ".xlsx"
DtString = Format(Now(), "mm-dd")
SName = itm.SenderName
File_Name = DtString & "_" & SName
Full_Path = saveFolder & "\" & File_Name

For Each objAtt In itm.Attachments
    objAtt.SaveAsFile Full_Path
    Set objAtt = Nothing
Next

End Sub

I've tried adding ".xslx" at the end, I've tried opening an instance of Excel, opening the file, save and close.

I've tried saving it as a Txt file and opening that. Any help is much appreciated.

change:

Full_Path = saveFolder & "\" & File_Name

to:

Full_Path = saveFolder & "\" & File_Name & strFileType

Save E-mail attachments to folder, Copy the code in a Standard module of your workbook, if you just started with VBA see this page. Where do I paste the code that I find on the internet. Read this​  We would like to show you a description here but the site won’t allow us.

Use the attachment file name.

objAtt.SaveAsFile saveFolder & "\" & objAtt.FileName

Excel VBA download attachment from specific fodler in outlook , Hello, I am looking to download the most recent attachment from a specific folder in outlook. Right now the macro looks to the default folder  Automatically download Outlook attachments to folder using VBA and Outlook rule To achieve this automation which automatically download and save Outlook attachments to a chosen folder, you need to create a VBA script and run this script with a rule to. Please do as follows: Press Alt + F11 keys to open the Microsoft Visual…

Should be

File_Name = DtString & "_" & SName & strFileType

Example

Option Explicit
Private Sub saveAttachtoDisk(itm As Outlook.MailItem)
    Dim objAtt As Outlook.Attachment
    Dim saveFolder As String
    Dim strFileType As String
    Dim DtString As String
    Dim SName As String
    Dim File_Name As String
    Dim Full_Path As String

    saveFolder = "\\path\path\path\path\Path\"

    strFileType = ".xlsx"

    DtString = Format(Now(), "mm-dd")

    SName = itm.SenderName

    File_Name = DtString & "_" & SName & strFileType

    Full_Path = saveFolder & File_Name
    Debug.Print Full_Path ' print on Immediate Window

    For Each objAtt In itm.Attachments
        objAtt.SaveAsFile Full_Path
        Set objAtt = Nothing
    Next

End Sub

Auto Download Outlook Email Attachment – Code in VBA by , Now when I want to do some analysis on the data I need to go through the inbox, search for that particular data and then download it to local. The  To ensure consistent results, always save an item before adding or removing objects in the Attachments collection of the item. Example. The following Visual Basic for Applications (VBA) example creates a new mail message, attaches a Q496.xls as an attachment (not a link), and gives the attachment a descriptive caption.

VBA-Excel — AttachmentFetcher, VBA-Excel — AttachmentFetcher — Download all the Attachments from All the Mails of Specific Subject in Microsoft Outlook . by SJ · Published  The following Microsoft Visual Basic /Visual Basic for Applications (VBA) example creates a mail item, adds an attachment by embedding it at the beginning of the message body, and displays it. To run this example, make sure the attachment which is a file called Test.Doc exists in the C:\ folder.

Outlook Attachment Download VBA edit, Hi Guys, I have an Outlook VBA script that works fine for me when the attachments have different names. The script lets me select the folder to  I'm trying to download and then open an Excel spreadsheet attachment in an Outlook email using VBA in Excel. How can I: Download the one and only attachment from the first email (the newest email

How to automatically download/save attachments from Outlook to a , hi, I have 150 outlook mails saved in a folder, each having an attachment. I want to download attachment from all to a folder, via VBA. Please  Save E-mail attachments to folder. Important read this : The code on this page is only working when you use Outlook as your mail program. Copy the code in a Standard module of your workbook, if you just started with VBA see this page.

Comments
  • Put a breakpoint (F9) on the objAtt.SaveAsFile instruction, run the code, then inspect the value of Full_Path (hover the mouse over the variable, or bring up the locals toolwindow, or Ctrl+G and ?Full_Path) - is it what you expect it to be? Looking at your code it seems you understand everything you need to fix this already: seems learning to use the debugger would be more beneficial than anything else.
  • Are your attachments actually xlsx files? If you save them manually from Outlook can you open them normally in excel?
  • @TimWilliams Yes, they're all xslx. Been processing them manually for months, and it's always the same file, so the file itself is good to go.
  • saveFolder already has a terminating backslash, so no need to add it again here: Full_Path = saveFolder & "\" & File_Name
  • This is how I had it originally, and it works. So thank you for reminding me. But I changed it since the file name is usually too long, and I use that file for importing to an ERP system, and it does not take long names.
  • You can try to retrieve the short file name using the GetShortPathName Windows API function - see mrexcel.com/forum/excel-questions/…