Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Thread Tools Display Modes
Old 12-01-2005, 11:28 AM
Chief96 Chief96 is offline
Saving file attachments
Join Date: Dec 2005
Posts: 1
Default Saving file attachments

I have a script that is supposed to read from a specific Public Folder to strip off file attachments on incoming emails. I am sure the scipt is correct but it does not run when Outlook starts. The script is supposed to run automatically when a new item shows up in that Public Folder. Here is the script.

Dim WithEvents NewMailItems As Outlook.Items
Private Sub Application_Startup()
Set NewMailItems = Application.GetNamespace("MAPI").GetDefaultFolder( olFolderInbox).Items
End Sub

Private Sub NewMailItems_ItemAdd(ByVal msg As Object)

Dim myNS As NameSpace
Dim myInbox As MAPIFolder
Dim targetAttach As Attachment
Dim Dest As MAPIFolder
Dim f1 As MAPIFolder
Dim f2 As MAPIFolder

' Get a reference to the Inbox.
Set myNS = GetNamespace("MAPI")
Set myInbox = myNS.GetDefaultFolder(olFolderInbox)

Set Dest = Nothing

For Each f1 In myNS.Folders
For Each f2 In f1.Folders
If f2.Name = "Outgoing Messages" Then
Set Dest = f2
End If

'Process only mail messages.
If TypeOf msg Is MailItem Then

'Does this new message have any attachments?
For Each targetAttach In msg.Attachments

'Does this attachment have .oft in the filename?
If InStr(1, targetAttach.FileName, ".oft", vbTextCompare) > 0 Then

'Save off mail attachment and delete the message.
targetAttach.SaveAsFile "C:\DBUSAVE\" & targetAttach.DisplayName


Exit For

End If


End If

End Sub
Reply With Quote

Thread Tools
Display Modes

Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel not saving all data and formatting TRT Excel 2 04-09-2009 12:51 PM
Saving Just one page.... derr04 Word 1 09-21-2007 10:46 AM
Saving only "DATA" on excel? No white bottom? Excel 0 08-07-2006 09:27 AM
Attachments Ane Outlook 0 05-29-2006 04:09 AM
Daylight Saving Time Changed all appointments nemeth Outlook 0 04-10-2006 01:33 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 10:34 PM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2023, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2023 DragonByte Technologies Ltd. is not affiliated with Microsoft