Solved

Get the email stuff

Posted on 2013-12-24
5
363 Views
Last Modified: 2013-12-24
Hello All,

I am looking for a some code in VBScript where it goes through folder AAA of my outlook and then downloads any email attachments that have a date stamp of either yesterday or today.

Can someone guide me in the right direction for this? or get me started...

Thank You
0
Comment
Question by:Rayne
  • 2
  • 2
5 Comments
 
LVL 3

Expert Comment

by:Caltor
ID: 39737697
I presume you mean VBA (executes inside of Outlook or other Office applications) and not VBScript (executes outside of Office in Windows Scripting Host). What version of Office/Outlook?
0
 

Author Comment

by:Rayne
ID: 39737700
Hello Caltor,

thank you for letting me know. I am in favor of something or some script that when eventually written, could be called by the Windows Task Scheduler so that it is done automatically daily at a time interval - in that case  - do you think VBScript might be more better than VBA?
On the other hand - Can VBA be called by the Windows Task Scheduler?

Thank you
0
 
LVL 27

Accepted Solution

by:
MacroShadow earned 500 total points
ID: 39737702
These should get you started:
' The following Outlook VBScript saves all attachments of all emails in a given folder
' to the c:\data2\ folder.
' Visit my SPSS web site: http://pages.infinit.net/rlevesqu/index.htm

Public Sub SaveAttachments()
    ' Save all attachments of emails in a given folder to c:\data2\
    ' Posted to the spss newsgroup by Raynald Levesque 2003/01/07
    Dim mynamespace As NameSpace
    Dim email As MailItem
    Dim atAttachs As Attachments
    Dim atAttach As Attachment
    Dim myfolder As MAPIFolder
    Dim myitem As MailItem
    Dim strPath As String
    Dim intCnt As Integer
    Dim intEmails As Integer

    strPath = "c:\data2\"
    Set mynamespace = Application.GetNamespace("MAPI")

    Set myfolder = mynamespace.PickFolder
    'Set myfolder = mynamespace.GetDefaultFolder(olFolderInbox)
    myfolder.Display

    ' Go through each email in the folder
    For intEmails = 1 To myfolder.Items.Count
        Set myitem = myfolder.Items(intEmails)
        'myitem.Display
        Debug.Print "# of attachemnts= " & myitem.Attachments.Count
        Set atAttachs = myitem.Attachments
        For intCnt = 1 To myitem.Attachments.Count
            'Go through each attachments
            Set atAttach = atAttachs(intCnt)
            atAttach.SaveAsFile (strPath & atAttach.FileName)
        Next
    Next intEmails

    End Sub

Open in new window

http://www.spsstools.net/Scripts/ImportExport/SaveAllAttachmentsInOutlookFolder.txt

dim item1
dim objsubject
dim pa
dim savename
dim savefolder
savefolder = "D:/temp/"
Set olApp=CreateObject("Outlook.Application")
 Set olns=olApp.GetNameSpace("MAPI")
 Set objFolder=olns.GetDefaultFolder(6)
 msgbox objfolder
 For each item1 in objFolder.Items
if item1.Unread=true then
objsubject = item1.subject
if objsubject = "*****Give the mail subject here*****" then
pa =  item1.Attachments(1).filename
savename = savefolder & pa
msgbox savename
item1.Attachments(1).SaveAsFile savename
end if
end if
Next 

Open in new window

http://sathish-cognos.blogspot.co.il/2011/07/vbscript-for-downloading-attachments.html
0
 

Author Comment

by:Rayne
ID: 39737714
Awesome MacroShadow, you are great!!
Thank you Sire...
0
 
LVL 27

Expert Comment

by:MacroShadow
ID: 39737726
You're welcome.
0

Featured Post

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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This process describes the steps required to Import and Export data from and to .pst files using Exchange 2010. We can use these steps to export data from a user to a .pst file, import data back to the same or a different user, or even import data t…
In this step by step procedure, you will come to know the details of creating an Outlook meeting in 2007, 2010, 2013 & 2016.
Learn how to make your own table of contents in Microsoft Word using paragraph styles and the automatic table of contents tool. We'll be using the paragraph styles in Word’s Home toolbar to help you create a table of contents. Type out your initial …
Learn how to create and modify your own paragraph styles in Microsoft Word. This can be helpful when wanting to make consistently referenced styles throughout a document or template.

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question