UKC

VBA Outlook code for saving specific file types

New Topic
This topic has been archived, and won't accept reply postings.
 Climber_Bill 17 Mar 2014
Hi,

To save me the time of re-inventing the wheel (and hours searching the web) has anyone written vba code to save specific file types from all emails in an Outlook folder?

I.e. save all attachments that have file extension *.xxx.

Thanks.

Rich.
 Neil Conway 17 Mar 2014
In reply to Richard White:

I find this a useful resource: http://vba-programmer.com/
OP Climber_Bill 17 Mar 2014
In reply to Neil Conway:

Thanks, that is really helpful.
 AndyC 17 Mar 2014
In reply to Richard White:
This is a very condensed snippit of some VBA I wrote to save attachments from all selected emails in Outlook. It might give you a starting point.

Running code in Outlook is not so straightforward as other office applications - for example, you will probably need to create a self-signed digital certificate to sign your project, otherwise it will not run after you close and reopen Outlook.


Public Sub RunActions()

Dim sFldr As String
Dim sExtn as string
Dim Item As Outlook.MailItem
Dim Atmt As Attachment

sFldr = "path" ' path to folder where you want to save"
sExtn = "ext" ' extension to search for

Dim objSelection As Outlook.Selection
Set objSelection = Application.ActiveExplorer.Selection

On Error GoTo errRunActions
For Each Item In objSelection
For Each Atmt In Item.Attachments
If GetExtension(Atmt.FileName) = sExtn then
Atmt.SaveAsFile sFldr & "" & Atmt.FileName
End If
Next
Next
On Error GoTo 0

Exit Sub

errRunActions:

MsgBox "Error occurred while saving attachments : " & vbCrLf & Err.Description, vbExclamation, "Saving attachments"

End Sub


Private Function GetExtension(f As String)

Dim a As Variant

GetExtension = ""
If InStr(f, ".") > 0 Then
a = Split(f, ".")
GetExtension = a(UBound(a))
End If

End Function
Post edited at 19:56

New Topic
This topic has been archived, and won't accept reply postings.
Loading Notifications...