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
Solved

detaching attachment from email

Posted on 2002-03-13
13
370 Views
Last Modified: 2010-05-02
is it possible to detach a file from an email which has been recieved automatically as the email arrives.

steps

1) computer has live email connection

2) outlook is loaded

3) software sitting there scanning email <- part of what I'm asking for

4) detects email and detaches the file.

Is this possible in VB or VBA,

rather have it in VBA

any idea's

cheers
Andy
0
Comment
Question by:andysalih
  • 6
  • 6
13 Comments
 
LVL 50

Accepted Solution

by:
Ryan Chong earned 100 total points
ID: 6860171
Hi andysalih,

Recently give comments for a similar question, here is what the previous asker ask for:

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

You can simply put this in a Timer, assign an Internal, with a certain periods it will execute the code above.

ryancys
0
 
LVL 50

Expert Comment

by:Ryan Chong
ID: 6860173
To detect Internet Connection:

http://www.freevbcode.com/ShowCode.Asp?ID=632
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6860830
listening...
0
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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.

 
LVL 3

Author Comment

by:andysalih
ID: 6861135
thanks all, I'm currently up to my eyes in programming for a company at the moment, so I will try the code in the next day or 2 to reward points,

PS

Will this work in VBA aswell ????

cheers

Andy

speak to you all soon
0
 
LVL 50

Expert Comment

by:Ryan Chong
ID: 6863381
Yes, basically this works in VBA also.

Make sure you add the M$ Outlook 9.0 Object Library from Reference and it should fine as well :)
0
 
LVL 3

Author Comment

by:andysalih
ID: 6864279
Thanks ryancys,

but it says when i try and run the code that the list1.additem box METHOD OR DATA OBJECT NOT FOUND which means that additem is not found for list1 properties, could this be moded to work in VBA.

cheers
Andy
0
 
LVL 50

Expert Comment

by:Ryan Chong
ID: 6864302
Sorry, In Access, combobox use RowSource Property rather that AddItem to add item to its list.

You can just ignore/ remark the line content: List1.AddItem

regards,
ryancys
0
 
LVL 50

Expert Comment

by:Ryan Chong
ID: 6864304
content = contain, bad english.. .
0
 
LVL 3

Author Comment

by:andysalih
ID: 6864901
thanks ryancys

could i put it in outlook vb editor under macros,

I've run it from there and its working but I dont understand how outlook can run the module automatically while outlook it open.

hmmm i dunno if you understood any of that.

you have been a great help even so, points will be rewarded even so.

cheers
Andy
0
 
LVL 3

Author Comment

by:andysalih
ID: 6864929
if you look under tools in outlook then macro's you will see visual basic editor,

could i put the code in there because thats where ive run it from and its working fine, but i want it to run upon receiving new email how do i make it run from that part of outlook

cheers
Andy
0
 
LVL 50

Expert Comment

by:Ryan Chong
ID: 6867609
Hi Andy,

So you want to auto-activate the save function when a new is received?

I'll try and get back to you :)
0
 
LVL 3

Author Comment

by:andysalih
ID: 6867641
yes please

many thanks

Andy
0
 
LVL 3

Author Comment

by:andysalih
ID: 6877593
Hi ryancys,

I've sorted it matey, just added it into outlook as a vba module,

thanks for your help

Andy
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

840 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