Modify VBS Script for Outlook

  • Thread starter Thread starter Massimo
  • Start date Start date
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 !
 
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?
 
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.
 
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
 
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
 
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.
 
Back
Top