Is there a macro i can use to save specific attacments to my desktop?

sucett

Board Regular
Joined
Dec 14, 2007
Messages
122
Hi,

I get daily emails with the subject lines Productivity Report dd.mm.yy sent to my inbox. I want the macro to locate the email and then save the attachement to my desktop as Hours Report mm.yy. It is ok to overwrite the existing file.

Thanks!
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
you could probably drive in from outlook with a custom rule that triggers vba code, that intercepts the message and looks at the subject, and acts upon that, it will then run so long as outlook is open and up and running

i have some code somewhere to intercept messages, just need to add the code for the save as and code to locate desktop, which I also have needs throwing together
 
Upvote 0
this is a sample section of code for running in outlook as a custom rule, which runs a script depending on what version of outlook you have, you will need to change the fred.txt bit accordingly and setup the rule, this code needs to be pasted as a module in ThisOutlookSession

'****
' Routine for a custom rule for incoming emails
' Assembled from various Internet resources, and trial and error
'
' Author Jim Ward
' Creation November 2007
'
'
'****
' Firstly give the routine a name it matters not the name what is important is defining
' the passed parameter as type MAILITEM. You can then create a rule and use the Run A Script
' option and the name of the routine is displayed. Without the parameter it will not be seen !!
'****

Sub IncomingCheck(IncomingMail As MailItem)
Dim strID As String
Dim olNS As Outlook.NameSpace
Dim olMail As Outlook.MailItem
Dim oParentFolder As Outlook.MAPIFolder

'****
' What is key about this method is that by grabbing the ID and processing it from there it
' circumvents any OUTLOOK intervention asking to be granted access to the ITEM for security
' purposes
'****

strID = IncomingMail.EntryID
Set olNS = Application.GetNamespace("MAPI")
Set olMail = olNS.GetItemFromID(strID)

If InStr(1, olMail.Subject, "Productivity Report", vbTextCompare) > 0 Then
Set myattach = olMail.Attachments
'****
' get the desktop location
'****

Set oWSS = CreateObject("WScript.Shell")
szDesktopPath = oWSS.SpecialFolders(szlocation)

myattach(1).SaveAsFile szDesktopPath & "fred.txt"
End If

'****
' Clear out memory, all done
'****

Set olMail = Nothing
Set olNS = Nothing

End Sub
 
Upvote 0
ooops line should read

myattach(1).SaveAsFile szDesktopPath & "\fred.txt"
 
Upvote 0

Forum statistics

Threads
1,225,521
Messages
6,185,458
Members
453,292
Latest member
Michandra02

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