Outlook VBA Extraction

NatetheGreat

Active Member
Joined
Nov 18, 2013
Messages
268
Hello All,

I have a folder in my outlook entitled "Flippering"

Each email in this folder has an attachment in it. I want to run some Outlook VBA code that will cycle through each email in the folder and save the attachment to a specified path on my local PC.

So far I have set a rule, which runs a script. That script is the following code

Code:
Sub FlipperExtract(itm As Outlook.MailItem)
Dim objatt As Outlook.Attachment
Dim savefolder As String
Dim dateformat
dateformat = Format(Now, "mmdd H-mm")
savefolder = "C:\Users\me\Desktop\Daily Reports\Flippering"
For Each objatt In itm.Attachments
objatt.SaveAsFile savefolder & "\" & objatt.DisplayName
 Set objatt = Nothing
 End If
 Next
 
 
End Sub


When I set the rule to run the script in the flippering folder now, for all messages, it isn't copying anything as I would expect.

Any ideas? I tried to write something that wasn't rule based, i.e. just a macro for ad-hoc extraction, but it failed on
Code:
Sub flipper()
Dim apploutlook As Outlook.Application
Dim nsoutlook As Outlook.NameSpace
Dim atmt As Attachment
Dim cfolder As Outlook.Folder
Set apploutlook = Outlook.Application
Set nsoutlook = apploutlook.GetNamespace("MAPI")

Set cfolder = Outlook.Application.GetNamespace("MAPI").Folders("Flippering")

Destfolder = "C:\Users\me\Desktop\Daily Reports\Flippering"
For Each Item In cfolder
    For Each atmt In Item.Attachments
        If atmt.FileName = "Flippering.xls" Then
        dateformat = Format(Now, "mmdd")
        FileName = Destfolder & dateformat & " " & atmt.FileName
        atmt.SaveAsFile FileName
        i = i + 1
        End If
      Next atmt
 Next Item
 
 End Sub

This code failed with "operation could not be found" on the set cfolder line.


I would prefer to have both of these working, the outlook rule based 1st example to continually populate as I receive these emails, and the ad-hoc one to strip everything out when and where needed.

Many Thanks
Nate
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
The best thing to do is run the code in debug mode, stepping through one line of code at a time. You will then be able to see the variable values etc. and perhaps find out why it is not working. The first bit of code should not compile because you have an "End If" without an associated "If". For the second bit of code, you are missing a "\" when setting the value for the "FileName" variable.
 
Upvote 0

Forum statistics

Threads
1,225,681
Messages
6,186,411
Members
453,352
Latest member
OrionF

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top