Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 376
  • Last Modified:

detaching attachment from email

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
andysalih
Asked:
andysalih
  • 6
  • 6
1 Solution
 
Ryan ChongCommented:
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
 
Ryan ChongCommented:
To detect Internet Connection:

http://www.freevbcode.com/ShowCode.Asp?ID=632
0
 
Richie_SimonettiCommented:
listening...
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
andysalihAuthor Commented:
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
 
Ryan ChongCommented:
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
 
andysalihAuthor Commented:
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
 
Ryan ChongCommented:
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
 
Ryan ChongCommented:
content = contain, bad english.. .
0
 
andysalihAuthor Commented:
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
 
andysalihAuthor Commented:
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
 
Ryan ChongCommented:
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
 
andysalihAuthor Commented:
yes please

many thanks

Andy
0
 
andysalihAuthor Commented:
Hi ryancys,

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

thanks for your help

Andy
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 6
  • 6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now