?
Solved

Get the email stuff

Posted on 2013-12-24
5
Medium Priority
?
386 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

This article describes a serious pitfall that can happen when deleting shapes using VBA.
If you troubleshoot Outlook for clients, you may want to know a bit more about the OST file before doing your next job. IMAP can cause a lot of drama if removed in the accounts without backing up.
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

719 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