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 7550963
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T10:21:17+00:00 2026-05-30T10:21:17+00:00

We use Outlook 2010 and receive emails with Excel attachments. We manually save the

  • 0

We use Outlook 2010 and receive emails with Excel attachments. We manually save the attachment in a sub-folder that we create within a divisional folder on a network drive.

What I’m curious about is if it’s possible to

  1. Use code to check incoming emails to see if they have an attachment,
  2. Then check the attachment to see if it’s an .XLSX,
  3. If so, open the attachment, check the value of a particular cell,
  4. then store the account name and account number as a string and a variable
  5. then use those to create the sub-folders in the appropriate Windows directory.

** I forgot to post what I had done so far. I believe Brett answered my ??, but maybe someone else would be able to use snippets of it.

Private Sub cmdConnectToOutlook_Click()
Dim appOutlook As Outlook.Application
Dim ns As Outlook.Namespace
Dim inbox As Outlook.MAPIFolder
Dim item As Object
Dim atmt As Outlook.Attachment
Dim filename As String
Dim i As Integer

Set appOutlook = GetObject(, "Outlook.Application")
Set ns = appOutlook.GetNamespace("MAPI")
Set inbox = ns.GetDefaultFolder(olFolderInbox)
i = 0 

If inbox.Items.Count = 0 Then
    MsgBox "There are no messages in the Inbox.", vbInformation, _
           "Nothing Found"
    Exit Sub
End If

For Each item In inbox.Items
  For Each atmt In item.Attachments

    If Right(atmt.filename, 4) = "xlsx" Then
        filename = "\\temp\" & atmt.filename
        atmt.SaveAsFile filename
       i = i + 1
    End If

  Next atmt
Next item

MsgBox "Attachments have been saved.", vbInformation, "Finished"

Set atmt = Nothing
Set item = Nothing
Set ns = Nothing

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-05-30T10:21:18+00:00Added an answer on May 30, 2026 at 10:21 am

    Having said it is lengthy here is one way to do it. My code from VBA Code to save an attachment (excel file) from an Outlook email that was inside another email as an attachment may also be of interest

    You will need to update your file path, and the cell range from the file that you are opening

    In my testing I sent a message to myself with a pdf file and an excel workbook with “bob” in the A1 in the first sheet

    The code below found the excel file, saved it, opened it, create a directory c:\temp\bob then killed the saved file

    Private Sub Application_NewMailEx _
        (ByVal EntryIDCollection As String)
    
    'Uses the new mail techniquer from http://www.outlookcode.com/article.aspx?id=62
    
    Dim arr() As String
    Dim lngCnt As Long
    Dim olAtt As Attachment
    Dim strFolder As String
    Dim strFileName As String
    Dim strNewFolder
    Dim olns As Outlook.NameSpace
    Dim olItem As MailItem
    Dim objExcel As Object
    Dim objWB As Object
    
    'Open Excel in the background
    Set objExcel = CreateObject("excel.application")
    
    'Set working folder
    strFolder = "c:\temp"
    
    On Error Resume Next
    Set olns = Application.Session
    arr = Split(EntryIDCollection, ",")
    On Error GoTo 0
    
    For lngCnt = 0 To UBound(arr)
        Set olItem = olns.GetItemFromID(arr(lngCnt))
        'Check new item is a mail message
        If olItem.Class = olMail Then
            'Force code to count attachments
            DoEvents
            For Each olAtt In olItem.Attachments
                'Check attachments have at least 5 characters before matching a ".xlsx" string
                If Len(olAtt.FileName) >= 5 Then
                    If Right$(olAtt.FileName, 5) = ".xlsx" Then
                        strFileName = strFolder & "\" & olAtt.FileName
                        'Save xl attachemnt to working folder
                        olAtt.SaveAsFile strFileName
                        On Error Resume Next
                        'Open excel workbook and make a sub directory in the working folder with the value from A1 of the first sheet
                        Set objWB = objExcel.Workbooks.Open(strFileName)
                        MkDir strFolder & "\" & objWB.sheets(1).Range("A1")
                        'Close the xl file
                        objWB.Close False
                        'Delete the saved attachment
                        Kill strFileName
                        On Error Goto 0
                    End If
                End If
            Next
        End If
    Next
    'tidy up
    Set olns = Nothing
    Set olItem = Nothing
    objExcel.Quit
    Set objExcel = Nothing
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Outlook 2010 We save .msg on the disk and we use COM API's to
I'm building an Outlook 2010 add-in that will tie into our ticketing system using
I have an Outlook 2010 addin, and I'm trying to create a custom context
I'm coding an Outlook 2010 plug-in in .NET 4.0, which use WPF technology, and
I'm working on an Outlook 2010 add-in that provides a dialog for user input.
I want to create a mail with attachment in Outlook and display it before
I'm wondering if I can use outlook express to create .MSG files using Visual
My company requires me to use Outlook for my E-mail. Outlook does virtually nothing
Rather than reinvent the wheel I would like to use Outlook to manage my
In an Outlook AddIn I'm working on, I use a list to grab all

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.