Solved

detaching attachment from email

Posted on 2002-03-13
13
369 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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VBA/SQL - Connect to SQL server and pull data 4 108
Access 2013 combo box not working 3 44
using web browser with BING 40 119
Passing a Text Box name to a Sub 6 96
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

786 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