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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Saving Attachments

Status
Not open for further replies.

robcarr

Programmer
Joined
May 15, 2002
Messages
633
Location
GB
Dear All,

Is there a way to save all Excel attachments in outlook to say "H:\Excel Files\" and then save all zipped files to say "H:\zipped Files\" automatically when they are received,(all attachemnts are stored in \Inbox\Attachments\ folder) I have looked around for coding to try and help with this, but i am having great difficulty in trying to get this to work. I have some coding below which a colleague sent to me but I am really new to outlook VBA and can't get this to work,can anybody help with this, does anybody also know how to open all files received today automatically in the public folders location of the files are as follows
Public Folders\All Public Folders\Crystal Reports\Client Reports\Client\Agent Reports\Bagpuss\, the files that are in here are saved as .doc files, the subject of the file each day is sag101.rpt, i need to open today's file with this subject, and also save this file to "H:\101 Reports\"

Any help on any of this would be greatly appreciated. If anybody knows of any good sites where I can get help on this would also be appreciated.
The coding as mentioned above.
'coding not in any order
Dim WithEvents myOlApp As Outlook.Application

Sub Initialize_handler()
Set myOlApp = CreateObject("Outlook.application")
End Sub

Private Sub myOlApp_NewMail()
Dim myExplorers As Outlook.Explorers
Dim myFolder As Outlook.MAPIFolder
Set myExplorers = myOlApp.Explorers
Set myFolder = myOlApp.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox)
If myExplorers.Count <> 0 Then
For x = 1 To myExplorers.Count
On Error GoTo skipif
If myExplorers.Item(x).CurrentFolder.Name = &quot;Inbox&quot; Then
myExplorers.Item(x).Display
myExplorers.Item(x).Activate
Exit Sub
End If
skipif:
Next x
End If
On Error GoTo 0
myFolder.Display
'this is my coding to save attachments

Sub Openemails()Set myOlApp = CreateObject(&quot;Outlook.Application&quot;)Set myNameSpace = myOlApp.GetNamespace(&quot;MAPI&quot;)Set mymails = myNameSpace.GetDefaultFolder(olFolderInbox)
Set myItem = mymails.Items.Find(&quot;[From] = &quot;&quot;Edwards, Clinton&quot;&quot;&quot;)
Set myAttachments = myItem.Attachments
With myItem
.DisplayEnd WithSet myAttachments = myItem.Attachments
myAttachments.Item(1).SaveAsFile &quot;C:\Rob\&quot; & _ myAttachments.Item(1).DisplayNameEnd Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top