Solved

detaching attachment from email

Posted on 2002-03-13
13
364 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 49

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 49

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
 
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 49

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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 49

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 49

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 49

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

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!

Join & Write a Comment

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
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…
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…
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…

706 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

20 Experts available now in Live!

Get 1:1 Help Now