+ Reply to Thread
Results 1 to 3 of 3

Saving file as a date

  1. #1
    Jamie
    Guest

    Saving file as a date

    Hi There

    I am using this code (which I got from here) to try to save email
    attachments to a folder. At the moment it saves the file as the name of the
    person sending it, which is what I want. However, if the same person was to
    send two, the second would overwrite the first. Ideally I'd like the date
    and time but someone suggested using & now() but this doesn't work as excel
    doesn't like the file path.

    Has anyone got any ideas?

    HAs anyone got

    Sub SaveAttachments()



    Dim olApp As Outlook.Application
    Dim olNs As NameSpace
    Dim Fldr As MAPIFolder
    Dim MoveToFldr As MAPIFolder
    Dim olMi As MailItem
    Dim olAtt As Attachment
    Dim MyPath As String
    Dim i As Long

    Set olApp = New Outlook.Application
    Set olNs = olApp.GetNamespace("MAPI")
    Set Fldr = olNs.GetDefaultFolder(olFolderInbox)
    Set MoveToFldr = Fldr.Folders("eisreq")
    MyPath = "I:\EIS\Forms\"

    For i = Fldr.Items.Count To 1 Step -1
    Set olMi = Fldr.Items(i)
    If InStr(1, olMi.Subject, "EIS") > 0 Then
    For Each olAtt In olMi.Attachments
    If olAtt.Filename = "EIS Request.xls" Then
    olAtt.SaveAsFile MyPath & olMi.SenderName &now() & ".xls"
    End If
    Next olAtt
    olMi.Save
    olMi.Move MoveToFldr
    End If
    Next i

    Set olAtt = Nothing
    Set olMi = Nothing
    Set Fldr = Nothing
    Set MoveToFldr = Nothing
    Set olNs = Nothing
    Set olApp = Nothing

    End Sub


    Any help would be really appreciated

    Thanks in advance

    Jamie

  2. #2
    Forum Contributor
    Join Date
    03-24-2004
    Location
    Edam Netherlands
    Posts
    181
    SaveTime = Hour(Now()) & Minute(Now()) & Second(Now())

  3. #3
    Andibevan
    Guest

    Re: Saving file as a date

    Jamie,

    Try:-.

    olAtt.SaveAsFile MyPath & olMi.SenderName & Format(Date, "yyyymmdd") & "_" &
    Format(Time,"hhmmss") & ".xls"

    You need to specify the the format for the date as it uses the characters :
    and / for the time and date.

    Regards

    Andy



    "Jamie" <[email protected]> wrote in message
    news:[email protected]...
    Hi There

    I am using this code (which I got from here) to try to save email
    attachments to a folder. At the moment it saves the file as the name of the
    person sending it, which is what I want. However, if the same person was to
    send two, the second would overwrite the first. Ideally I'd like the date
    and time but someone suggested using & now() but this doesn't work as excel
    doesn't like the file path.

    Has anyone got any ideas?

    HAs anyone got

    Sub SaveAttachments()



    Dim olApp As Outlook.Application
    Dim olNs As NameSpace
    Dim Fldr As MAPIFolder
    Dim MoveToFldr As MAPIFolder
    Dim olMi As MailItem
    Dim olAtt As Attachment
    Dim MyPath As String
    Dim i As Long

    Set olApp = New Outlook.Application
    Set olNs = olApp.GetNamespace("MAPI")
    Set Fldr = olNs.GetDefaultFolder(olFolderInbox)
    Set MoveToFldr = Fldr.Folders("eisreq")
    MyPath = "I:\EIS\Forms\"

    For i = Fldr.Items.Count To 1 Step -1
    Set olMi = Fldr.Items(i)
    If InStr(1, olMi.Subject, "EIS") > 0 Then
    For Each olAtt In olMi.Attachments
    If olAtt.Filename = "EIS Request.xls" Then
    olAtt.SaveAsFile MyPath & olMi.SenderName &now() &
    ".xls"
    End If
    Next olAtt
    olMi.Save
    olMi.Move MoveToFldr
    End If
    Next i

    Set olAtt = Nothing
    Set olMi = Nothing
    Set Fldr = Nothing
    Set MoveToFldr = Nothing
    Set olNs = Nothing
    Set olApp = Nothing

    End Sub


    Any help would be really appreciated

    Thanks in advance

    Jamie



+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1