[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 358
  • Last Modified:

Need to Save Outlook Attatchment to local or network folder (macro?)

Hello,

I am constantly recieving an email from the same person, with a very similar subject line every day. I want to enable my outlook program to save the attatchment to a local or network path while I am away.

Any ideas on how to approach this problem?
I assume the best way to do this is through an outlook macro? Any code would help greatly.


Thanks
0
KrisTheComputerGuy
Asked:
KrisTheComputerGuy
  • 9
  • 7
1 Solution
 
Chris BottomleyCommented:
Hello KrisTheComputerGuy,

You can create a rule and run a script.  The function of the script would be to save the file ... is that acceptable, and if so will the rule establish the correct email such that only one attachment will be found and does it overwrite any pre-existing file of the same name?

Regards,

chris_bottomley
0
 
KrisTheComputerGuyAuthor Commented:
I've never written a script for outlook. Though I'm confident that I can modify anything to tweak it as needed. I have some experiences with C++, Java & C#.

You are correct as far as the purpose of the script. Multiple attachments may exist. But the file names aren't a problem since the files are dated in the filenames. I may have to place the files in a different folder for each date.

Some code would be awesome.

Thanks!
0
 
Chris BottomleyCommented:
Happy to do the code for you ...since filenames are no issue and you want the files saving under a dated folder can you indicate that a single root folder will be used for all saves and the format for the dated folders, (i.e. yyyy mm dd or yyyy mm for example).

Chris
0
Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

 
KrisTheComputerGuyAuthor Commented:
yep, I just have no idea how to get started. Outlook help doesn't really help : /
0
 
OmnicefCommented:
This might be an easier way, it isn't free, but for only $40 it is probably worth it. The have a free trial so you can try it first.

http://www.softsea.com/review/Attachment-Auto-Saver-for-Outlook.html
0
 
KrisTheComputerGuyAuthor Commented:
I found this:

http://www.outlookcode.com/codedetail.aspx?id=1494

I haven't used it yet. I won't close the question until I test it.
0
 
Chris BottomleyCommented:
How to get started is my domain ... if you can advise on root folder and sub folder naming convention I can sort ity out

Chris
0
 
Chris BottomleyCommented:
If it works for you then fine but note you originally suggested they should be saved to dated sub folders off a master folder ... I don't think they are in that case but as I say enough is enough is it works for you.

Chris
0
 
KrisTheComputerGuyAuthor Commented:
oh, i was just thinking YYYYMMDD, being the day that the file was downloaded. Nothing too fancy.
0
 
Chris BottomleyCommented:
Do you need some help in creating a rule for the purpose of triggering some code?

Chris
0
 
Chris BottomleyCommented:
The following is the code that will hopefully do what you want.  I appreciate you will want help and once I know how much help then we can start.

To Record a macro:
------------------

Tools | Macro | Record New Macro, (Stop recording button or Tools | Macro | Stop Recording at end)

To Create a macro:
------------------

Alt + F11 to open the macro editor

  For User Code:
     Insert | Module to insert a code module into the project
     In the project tree select the module.
     Insert the required macro(s) into the selected module, ('Module1' or similar)

Close the Visual Basic Editor.

Check Security as appropriate:
------------------------------

In the application select Tools | Macro | Security
2003 and Earlier : Select Medium
2007 : Warnings for all Macros
Select OK

Chris
Sub delSaveAttachSenderBase(mai As mailitem)
Dim dosFolderPath As String
Dim intIncrement As Integer
Dim intAtt As Integer
Dim att As Attachment
Dim fn As String
Dim ft As String
Dim FSO As Object
Dim maiDate As String

    dosFolderPath = "c:\deleteme\"
    If Right(dosFolderPath, 1) <> "\" Then dosFolderPath = dosFolderPath & "\"
        Set FSO = CreateObject("scripting.filesystemobject")
        maiDate = Format(mai.ReceivedTime, "yyyy mm dd")
        dosFolderPath = dosFolderPath & maiDate & "\"
        md dosFolderPath, True
        For intAtt = mai.Attachments.count To 1 Step -1
            Set att = mai.Attachments(intAtt)
            intIncrement = 1
            fn = Left(att.FileName, InStrRev(att.FileName, ".") - 1)
            ft = Right(att.FileName, Len(att.FileName) - InStrRev(att.FileName, ".") + 1)
            Do While FSO.FileExists(dosFolderPath & fn & "_" & intIncrement & ft)
                intIncrement = intIncrement + 1
            Loop
            att.SaveAsFile dosFolderPath & fn & "_" & intIncrement & ft
'            att.Delete
        Next
'        mai.Save

Set FSO = Nothing
End Sub

Function md(dosPath As String, Optional createFolders As Boolean)
Dim FSO As Object
Dim fldrs() As String
Dim rootdir As String
Dim fldrIndex As Integer
    
    md = True
    Set FSO = CreateObject("Scripting.FileSystemObject")
    If Not FSO.FolderExists(dosPath) Then
        fldrs = Split(dosPath, "\")
        rootdir = fldrs(0)
        If Not FSO.FolderExists(rootdir) Then
            md = False
            Exit Function
        End If

        For fldrIndex = 1 To UBound(fldrs)
            rootdir = rootdir & "\" & fldrs(fldrIndex)
            If Not FSO.FolderExists(rootdir) Then
                If createFolders Then
                    FSO.CreateFolder rootdir
                Else
                    md = False
                End If
            End If
        Next
        Exit Function
    End If
End Function

Open in new window

0
 
KrisTheComputerGuyAuthor Commented:
This looks good. I'll try it out Monday morning and see what happens.
0
 
Chris BottomleyCommented:
Catch you next week then

Chris
0
 
KrisTheComputerGuyAuthor Commented:
Thanks for the code. It is very robust!

However, Outlook 2003 produced a scripting error for the md command, saying that it doesn't exist.

The script worked after I commented out the following lines
      '  dosFolderPath = dosFolderPath & maiDate & "\"
      '  md dosFolderPath, True

Is there another make directory like command I can use instead of md?
0
 
Chris BottomleyCommented:
Function MD was at the end of the code I supplied and should be placed in a normal code module

VBE | Insert | Module

Chris
0
 
KrisTheComputerGuyAuthor Commented:
Works like a charm. You Rock!
0
 
Chris BottomleyCommented:
Glad to help

Chris
0

Featured Post

Veeam and MySQL: How to Perform Backup & Recovery

MySQL and the MariaDB variant are among the most used databases in Linux environments, and many critical applications support their data on them. Watch this recorded webinar to find out how Veeam Backup & Replication allows you to get consistent backups of MySQL databases.

  • 9
  • 7
Tackle projects and never again get stuck behind a technical roadblock.
Join Now