Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7845809
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T17:22:03+00:00 2026-06-02T17:22:03+00:00

I’m trying to create a VBA macro that saves an email attachment to folder

  • 0

I’m trying to create a VBA macro that saves an email attachment to folder depending on the email address. For example if I receive and email with an attachment from joey@me.com I want to save that attachment to the directory
\server\home\joey
or if I receive it from steve@me.com the attachment should be saved in
\server\home\steve .

And finally I want send a reply email with the name of the file that has been saved. I found some code that almost does what I want but I having a difficult time modifying it. This is all being done in Outlook 2010. This is what I have so far. Any help would be greatly appreciated

Const mypath = "\\server\Home\joe\"
Sub save_to_v()

    Dim objItem As Outlook.MailItem
    Dim strPrompt As String, strname As String
    Dim sreplace As String, mychar As Variant, strdate As String
    Set objItem = Outlook.ActiveExplorer.Selection.item(1)
    If objItem.Class = olMail Then

        If objItem.Subject <> vbNullString Then
            strname = objItem.Subject
        Else
            strname = "No_Subject"
        End If
        strdate = objItem.ReceivedTime

        sreplace = "_"

        For Each mychar In Array("/", "\", ":", "?", Chr(34), "<", ">", "|")

            strname = Replace(strname, mychar, sreplace)
            strdate = Replace(strdate, mychar, sreplace)
        Next mychar

        strPrompt = "Are you sure you want to save the item?"
        If MsgBox(strPrompt, vbYesNo + vbQuestion) = vbYes Then
            objItem.SaveAs mypath & strname & "--" & strdate & ".msg", olMSG
        Else
            MsgBox "You chose not to save."
        End If
    End If
End Sub
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T17:22:05+00:00Added an answer on June 2, 2026 at 5:22 pm

    Is this what you are trying? (UNTESTED)

    Option Explicit
    
    Const mypath = "\\server\Home\"
    
    Sub save_to_v()
    
        Dim objItem As Outlook.MailItem
        Dim strPrompt As String, strname As String, strSubj As String, strdate As String
        Dim SaveAsName As String, sreplace As String
        Dim mychar As Variant
    
        Set objItem = Outlook.ActiveExplorer.Selection.Item(1)
    
        If objItem.Class = olMail Then
    
            If objItem.Subject <> vbNullString Then
                strSubj = objItem.Subject
            Else
                strSubj = "No_Subject"
            End If
    
            strdate = objItem.ReceivedTime
    
            sreplace = "_"
    
            For Each mychar In Array("/", "\", ":", "?", Chr(34), "<", ">", "|")
                strSubj = Replace(strSubj, mychar, sreplace)
                strdate = Replace(strdate, mychar, sreplace)
            Next mychar
    
            strname = objItem.SenderEmailAddress
    
            strPrompt = "Are you sure you want to save the item?"
    
            If MsgBox(strPrompt, vbYesNo + vbQuestion) = vbYes Then
                Select Case strname
                Case "joey@me.com"
                    SaveAsName = mypath & "joey\" & strSubj & "--" & strdate & ".msg"
                Case "steve@me.com"
                    SaveAsName = mypath & "steve\" & strSubj & "--" & strdate & ".msg"
                End Select
    
                objItem.SaveAs SaveAsName, olMSG
            Else
                MsgBox "You chose not to save."
            End If
        End If
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to create a recordset in Access VBA that will show me
I'm trying to make a macro in VBA for Delmia. That macro need to
I’m using VBA in Outlook 2010 and I’m trying to create a function that
I'm trying to create a macro that produces in-cell graphing as seen over at
I am trying to create a VBA code that will run through each distinct
I am trying create a WCF service that leverages the WPF MediaPlayer on the
Trying to create my first iPhone app that would play back audio. When I
I'm trying to create a COM Class Library for my VBA Project and one
I am trying to create a stacked column chart in VBA where there is
I am trying to create some VBA code to automate dashboard creation against a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.