Modify VBS Script for Outlook

M

Massimo

Hi,
I find at this link:
http://www.microsoft.com/italy/tech...nter/resources/officetips/aug05/tips0809.mspx
a script to save all the outlook attachment in a folder, the script is:

--------------------------------------------------
Const olFolderInbox = 6
Set objOutlook = CreateObject("Outlook.Application")
Set objNamespace = objOutlook.GetNamespace("MAPI")
Set objFolder = objNamespace.GetDefaultFolder(olFolderInbox)
Set colItems = objFolder.Items
For Each objMessage in colItems
intCount = objMessage.Attachments.Count
If intCount > 0 Then
For i = 1 To intCount
objMessage.Attachments.Item(i).SaveAsFile "C:\Temp\" & _
objMessage.Attachments.Item(i).FileName
Next
End If
Next
--------------------------------------------------

My problem is that I would like to save only the attachment of a specified
sender and not all,
anyone help me to modify the script ?

Thank you very much !
 
K

Ken Slovak - [MVP - Outlook]

How would this sender be identified? Is it someone in an existing contact
item, or based on the sender name or sender email address? What version of
Outlook? Where is this script running, is it in Outlook?
 
M

Massimo

How would this sender be identified? Is it someone in an existing contact
item, or based on the sender name or sender email address? What version of
Outlook? Where is this script running, is it in Outlook?

Hi,
I would like to identify the sender by email address or display name, the
script
run on my desktop (external Outlook), my version of Outlook is 2003.

Thank you very much.
 
K

Ken Slovak - [MVP - Outlook]

In Outlook 2003 you can use the MailItem.SenderName and
MailItem.SenderAddress properties. Once you get each mail item in the loop
use those properties:

For Each objMessage in colItems
If ((objMessage.SenderName = "Joe Fubar") OR _
(objMessage.SenderAddress = "(e-mail address removed)")) Then

' do whatever with this one
End If
 
M

Massimo

MailItem.SenderAddress properties. Once you get each mail item in the loop
use those properties:

For Each objMessage in colItems
If ((objMessage.SenderName = "Joe Fubar") OR _
(objMessage.SenderAddress = "(e-mail address removed)")) Then

' do whatever with this one
End If


Thank you very much but I'm ignorant about VBS :)
how can I modify the script with the new option ?

--------------------------------------------------
Const olFolderInbox = 6
Set objOutlook = CreateObject("Outlook.Application")
Set objNamespace = objOutlook.GetNamespace("MAPI")
Set objFolder = objNamespace.GetDefaultFolder(olFolderInbox)
Set colItems = objFolder.Items
For Each objMessage in colItems
intCount = objMessage.Attachments.Count
If intCount > 0 Then
For i = 1 To intCount
objMessage.Attachments.Item(i).SaveAsFile "C:\Temp\" & _
objMessage.Attachments.Item(i).FileName
Next
End If
Next
 
K

Ken Slovak - [MVP - Outlook]

Const olFolderInbox = 6
Set objOutlook = CreateObject("Outlook.Application")
Set objNamespace = objOutlook.GetNamespace("MAPI")
Set objFolder = objNamespace.GetDefaultFolder(olFolderInbox)
Set colItems = objFolder.Items
For Each objMessage in colItems
intCount = objMessage.Attachments.Count
If intCount > 0 Then
For i = 1 To intCount
If ((objMessage.SenderName = "Joe Fubar") OR _
(objMessage.SenderAddress = "(e-mail address removed)")) Then

objMessage.Attachments.Item(i).SaveAsFile "C:\Temp\" & _
objMessage.Attachments.Item(i).FileName
End If
Next
End If
Next

You have to substitute the actual name and email address you want of course.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top