Solved

Download attachment from Outlook.

Posted on 2002-05-31
13
1,635 Views
Last Modified: 2012-05-04
I would like to develope a service in visual basic 6.0, which downloads the attacthment from the outlook and save it in the particular folder. As soon as user receive a mail with an attachment, that attachment will be downloaded in the folder. The mails which are coming is from various clients about 50 clients. Pls give me the solution. If u can send me the some kind of code also then it will be beneficial to me.
0
Comment
Question by:jeet_nbi
13 Comments
 
LVL 49

Expert Comment

by:Ryan Chong
ID: 7046526
Answer this similar question before, let me do a quick search first :)
0
 
LVL 49

Expert Comment

by:Ryan Chong
ID: 7046535
Still find original solution, but you can refer to this also:

Save Attachments From the Outlook Inbox to a File:
http://www.freevbcode.com/ShowCode.Asp?ID=1154
0
 
LVL 49

Accepted Solution

by:
Ryan Chong earned 50 total points
ID: 7046551
Here is it:

Read the Inbox Folder to see if it's a New Email, if it got attachments, save it into specified directory:

Private Sub Command3_Click()
   Dim iOutlook As Outlook.Application
   Dim myitem As Outlook.MailItem
   Dim myFolder As Outlook.MAPIFolder
   Dim myAttach As Outlook.Attachment
   Set iOutlook = New Outlook.Application
   
   Set myFolder = iOutlook.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox)

   List1.Clear
   For i = 1 To myFolder.Items.Count
       Set myitem = myFolder.Items(i)
       If myitem.UnRead = True And myitem.Attachments.Count > 0 Then 'If the Item is UnRead and With
Attachment(s)
           List1.AddItem myitem.SenderName & " " & myitem.Subject
           For j = 1 To myitem.Attachments.Count
               Set myAttach = myitem.Attachments(j)
               myAttach.SaveAsFile "D:\" & myAttach.FileName
           Next j
           DoEvents
       End If
   Next i
   Set myitem = Nothing
   Set myFolder = Nothing
   Set iOutlook = Nothing
End Sub

* Remove the myitem.UnRead = True  from the code above if you want to check all the mails in Inbox folder.

regards,
ryancys
0
 

Author Comment

by:jeet_nbi
ID: 7046620
Dear Ryancys,
Thanks for your prompt reply. But sorry to say that code is giving me the problem. While running the following code its giving me the type mismatch error.
Set myitem = myFolder.Items(i)
Please solve my problem. Its Urgent.

Thanks
Jeetendra

0
 
LVL 49

Expert Comment

by:Ryan Chong
ID: 7046645
Forget to tell, you need to add the M$ Outlook 9.0 Object Library from your References. Add this reference and run the code above again, it should working well.

regards
0
 
LVL 49

Expert Comment

by:Ryan Chong
ID: 7050502
Hi jeet_nbi,

Any progress? The code above tested to be working.
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:jeet_nbi
ID: 7051123
Hi Ryancys,
I don't have the Outlook 8.0 library. As soon as i get it i will try and get back to u. Thanks again.
Jeet.
0
 

Author Comment

by:jeet_nbi
ID: 7051125
Sorry I don't have the outlook library 9.0. I have 8.0.

jeet
0
 
LVL 49

Expert Comment

by:Ryan Chong
ID: 7053113
It's ok, so you got office/outlook 97 (let me guess)? Just add this reference (8.0) in your project and try to run the code above.
0
 

Author Comment

by:jeet_nbi
ID: 7055511
Hi Ryancys,
I have got the msoutl9.olb file and copy it in the system32 directory, and given the reference in the project.I have tried to run the project but its gives me the error :Variables uses an automation type does not supported in VB while creating the outlook application object. Earlier I had tried this with lib 8.0, every thing was ok, outlook application object was created, but gives me a error while creating mailitem object. Now give me the solution.
Thanks for the help.
Jeet
0
 
LVL 49

Expert Comment

by:Ryan Chong
ID: 7055551
I think you can't just copy the msoutl9.olb to system, this is a wrong step. For your information, the msoutl9.olb is for Office 2k (outlook 2k), so it involve the installation of office 2k. Make sure you install office 2k in proper way.

The references in VB project is simple:

M$ Outlook Object 8.0 Library is for Outlook 97, 9.0 is for Outlook 2000, 10.0 is for Outlook XP.

It's depends on the client's pc and their requirement to determine which library to use, but basically for safety use the lower version of library, if the code not run smoothly, upgrade the library to higher level.

regards,
ryancys
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 7851324
Hi jeet_nbi,
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 ryancys's comment(s) as an answer.

jeet_nbi, 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:SpideyMod
ID: 7912901
per recommendation

SpideyMod
Community Support Moderator @Experts Exchange
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…

708 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

16 Experts available now in Live!

Get 1:1 Help Now