Results 1 to 5 of 5

Thread: Export specific outlook attachments

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2023
    Posts
    2

    Red face Export specific outlook attachments

    Good evening,

    I'm having a bit of trouble. I'm also not the MOST savvy at VBA, I just know enough to be dangerous, so bear with me if it seems a pre-schooler wrote this.

    I have a small VBA code that I run in outlook that works perfect. But I need to add to it, and am having trouble (it's also possible that what I want to accomplish, isn't doable).


    The current VBA does the following:
    Daily email comes from HR with an attached list of active employees.
    The VBA saves the attachment to a specific folder, while also archiving yesterday's file and adding a date to the naming convention and moving it to a hidden archive folder, so no files get overwritten.
    Email gets moved to the deleted folder.


    What I want/hope to add is this:
    Every Monday I receive 12 autogenerated emails with a report attached and I was hoping to add them to the mix.
    Email is received with report named X, vba saves it to folder Y, and archives the previous day's report to folder Z.


    Here is the current VBA for reference:

    Public Sub AttachmentsToDisk (MItem As Outlook.Mailitem)

    Name "L:\Client_Audits\Common AuditQ\ORG Charts\Hold\Active Employees with Legal Name & Remote status.xlsx"_
    As "L:Client_Audits\Common Audit Q\ORG Charts\Hold\Archive\Active Employees with Legal Name & Remote status" & Format(Now()-1,"MM.DD.YYYY") & ".xlsx"

    Dim oAttachment As Outlook.Attachment
    Dim sSaveFolder As String
    sSaveFolder = "L:\Client_Audits\Common Audit Q\ORG Charts\Hold"
    For Each oAttachment In MItem.Attachments
    oAttachment.SaveAsFile sSaveFolder & "Active Employees with Legal Name & Remote status.xlsx"
    Next

    End sub





    Any help would be MUCHHHH appreciate.

    Thanks,

    Newb.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,227

    Re: Export specific outlook attachments

    Is this really VBA or is it VB.NET? You have posted in the VB.NET forum and the code does look like VB.NET. That said, this bit doesn't seem to make sense:
    Code:
    Name "L:\Client_Audits\Common AuditQ\ORG Charts\Hold\Active Employees with Legal Name & Remote status.xlsx"_
    As "L:Client_Audits\Common Audit Q\ORG Charts\Hold\Archive\Active Employees with Legal Name & Remote status" & Format(Now()-1,"MM.DD.YYYY") & ".xlsx"
    Have you transcribed that incorrectly?

  3. #3

    Thread Starter
    New Member
    Join Date
    Nov 2023
    Posts
    2

    Re: Export specific outlook attachments

    It's transcribed correctly. It's just the line to archive the previous days' file before exporting today's file.

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,227

    Re: Export specific outlook attachments

    Quote Originally Posted by SophieMakescakes View Post
    It's transcribed correctly.
    If this really is VB.NET then that's not valid syntax, so it makes no sense. If it's VBA (it doesn't look like it but I'm not much of an expert) then you're in the wrong forum. Please clarify.

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,227

    Re: Export specific outlook attachments

    Actually, I just looked more closely and I can see elsewhere some code that would be valid in VBA but not VB.NET, so I'm going to assume that you're in the wrong forum and move this thread to Office Development.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width