Solved

Get the email stuff

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

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 26

Expert Comment

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

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

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…
Outlook Free & Paid Tools
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.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

760 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

18 Experts available now in Live!

Get 1:1 Help Now