Solved

Download attachment from Outlook.

Posted on 2002-05-31
13
1,648 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
13 Comments
 
LVL 52

Expert Comment

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

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 52

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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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 52

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 52

Expert Comment

by:Ryan Chong
ID: 7050502
Hi jeet_nbi,

Any progress? The code above tested to be working.
0
 

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 52

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 52

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
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…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month3 days, 13 hours left to enroll

630 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