Get the email stuff

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
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

MacroShadowConnect With a Mentor Commented:
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:

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)

    ' Go through each email in the folder
    For intEmails = 1 To myfolder.Items.Count
        Set myitem = myfolder.Items(intEmails)
        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 intEmails

    End Sub

Open in new window

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

Open in new window
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?
RayneAuthor Commented:
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
RayneAuthor Commented:
Awesome MacroShadow, you are great!!
Thank you Sire...
You're welcome.
All Courses

From novice to tech pro — start learning today.