I need a VBS script to automatically download files from my email, but I need the file name to be the email subject.

Mallory Holland 1 Reputation point
2023-01-04T17:08:13.19+00:00

My current VBS script saves the file to the drive I need and as the file's name, but it saves the attachment as a generic file, and when I open it up, it is a string. All the attachments are Excel files, but I cannot figure out why they were saved as generic files. I know it has to do with me saving the attachments as the email subject because I originally had the file saved as the attachment name. I need outlook to automatically download my excel files and save them to my folder.

Current Script

Public Sub SaveAttachmentsToDisk(MItem As Outlook.MailItem)
Dim oAttachment As Outlook.Attachment
Dim sSaveFolder As String
Dim objSubject As String
sSaveFolder = "H:\Outlook Attachments\"
For Each oAttachment In MItem.Attachments
oAttachment.SaveAsFile sSaveFolder & MItem.Subject
Next
End Sub

Original Script
Public Sub SaveAttachmentsToDisk(MItem As Outlook.MailItem)
Dim oAttachment As Outlook.Attachment
Dim sSaveFolder As String
sSaveFolder = "H:\Outlook Attachments\"
For Each oAttachment In MItem.Attachments
oAttachment.SaveAsFile sSaveFolder & oAttachment.DisplayName
Next
End Sub

P.s. I am not sure if I used the right tags, I could not find a tag for vbscript

Microsoft 365 and Office Development Other
Outlook Windows Classic Outlook for Windows For business
Developer technologies Visual Basic for Applications
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Victor Ivanidze 101 Reputation points
    2023-01-04T19:11:31.993+00:00

    It looks you need to hire a developer.

    0 comments No comments

  2. Oskar Shon 866 Reputation points
    2023-01-04T19:16:46.573+00:00

    Your line can be a success but Subject has no extinction

    oAttachment.SaveAsFile sSaveFolder & MItem.Subject  
    

    Then you should add in from original DisplayName
    Can you?
    And if you have more then One attachment then you should be sure do not overwriting :)

    Regards.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.