Solved

Get the email stuff

Posted on 2013-12-24
5
359 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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Sometimes Outlook might have problems sending a message. There may be various causes- corrupted PST, AV scanner etc. The message, instead of going to the Sent Items folder, sits in the Outbox indefinitely. To remove it you can use a free tool cal…
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
The viewer will learn how to  create a slide that will launch other presentations in Microsoft PowerPoint. In the finished slide, each item launches a new PowerPoint presentation and when each is finished it automatically comes back to this slide: …

947 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now