Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Download attachment from Outlook.

Posted on 2002-05-31
13
Medium Priority
?
1,653 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 53

Expert Comment

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

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 53

Accepted Solution

by:
Ryan Chong earned 200 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

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 53

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 53

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 53

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 53

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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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 utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

664 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