Solved

VB and MS Exchange

Posted on 2002-03-05
3
131 Views
Last Modified: 2010-05-02
I am looking to create a routine that will extract any attachments that come into an exchange mailbox.  For example, we have a weekly timesheet that is filled out in excel.  It is then emailed to the administator.  The only mail that is coming into this box are the timesheets.  What we are wanting is that once the attachment is recevied in the box, it will save to a network share.

1) Would this be done at the time the mail is received in the box or at the time it is received in outlook?

2)  Once determined when, how would it be done?


Any help is appreciated.

Thanks
0
Comment
Question by:GTLoner
3 Comments
 
LVL 28

Accepted Solution

by:
vinnyd79 earned 75 total points
ID: 6844191
In regards to your second question ....
This will extract all attachments from the inbox.
First you will need to add a reference to the Outlook Object Library,then create a form with a command button.
This example assumes you have a folder called C:\Attachments to save the files to.You might want to modify this to delete the mail item after saving the attachment.You might also want to check if the attachments exists before saving otherwise an attachment with the same name will get overwritten.Do the timesheets have different names? Do you need to save these files as soon as they arrive? If not maybe you can use a timer routine to run every 5 minutes or so?

Private Sub Command1_Click()
Dim oApp As Outlook.Application
Dim oNameSpace As NameSpace
Dim oFolder As MAPIFolder
Dim oMailItem As Object
Dim sMessage As String

Set oApp = New Outlook.Application
Set oNameSpace = oApp.GetNamespace("MAPI")
Set oFolder = oNameSpace.GetDefaultFolder(olFolderInbox)
For Each oMailItem In oFolder.Items
With oMailItem
If oMailItem.Attachments.Count > 0 Then
  On Error Resume Next
  oMailItem.Attachments.Item(1).SaveAsFile "C:\Attachments\" & oMailItem.Attachments.Item(1).FileName
End If
End With
Next oMailItem

Set oMailItem = Nothing
Set oFolder = Nothing
Set oNameSpace = Nothing
Set oApp = Nothing
End Sub

0
 
LVL 49

Expert Comment

by:DanRollins
ID: 7591796
Hi GTLoner,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:

    Accept vinnyd79's comment(s) as an answer.

GTLoner, if you think your question was not answered at all or if you need help, just post a new comment here; Community Support will help you.  DO NOT accept this comment as an answer.
==========
DanRollins -- EE database cleanup volunteer
0
 

Expert Comment

by:modulo
ID: 7624119
Finalized as proposed

modulo

Community Support Moderator
Experts Exchange
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now