Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Automtatically saving an attachment

Status
Not open for further replies.

sdempsey

Programmer
Mar 23, 2005
36
0
0
GB
Sorry about this. I posted this orginally on the Outlook forum and had no response. So thought this is perhaps a better forum.

I am trying to automatically save an attachment after it enters the inbox.I thought I would create a rule doing the following:-

Automatically run a script via a rule after an email enters the inbox and then move it to a dealt with folder.

I have added some VB script (found on the forum) to the VB editor. The is a public function I have created.

Then I have created a rule and run a script by selecting the public function.

But nothing happens.

The script is shown below: -


Public Sub Attachment_Save(objMailItem As MailItem)


Dim Outlook
Set Outlook = CreateObject("Outlook.Application")

FilePath = "c:\Downloads" 'attachment will be saved here

k = 1
j = Outlook.Session.Folders.Count

For i = 1 To Outlook.Session.Folders.Item(j).Folders.Count
Set Folder_Item = Outlook.Session.Folders.Item(j).Folders.Item(i)

If Folder_Item.Name = "Inbox" Then

For Each Mail_Item In Folder_Item.Items
IsTifFile = False

For Each Att_Item In Mail_Item.Attachments

FileName = FilePath & "\" & Att_Item
Att_Item.SaveAsFile FileName
k = k + 1
IsTifFile = True
Next
Next
End If
Next




End Sub

I not sure if I need all this script as I am just wanting to save the attachments coming into the inbox? Ideally with the file name based on the date/time of the computer to ensure they are all different.

Thanks in advance.
 
can you get the script to do anything at all?
can you confirm that your script is being run? (perhaps a msgbox in your script so you can debug what is happening?
perhaps some logging in a temp.txt file of what is happening in your script?

does your script work when you run it manually?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top