Go Back   AnandTech Forums > Software > Programming

· Hardware and Technology
· CPUs and Overclocking
· Motherboards
· Video Cards and Graphics
· AMD Video Cards
· Nvidia
· Displays
· Memory and Storage
· Power Supplies
· Cases & Cooling
· SFF, Notebooks, Pre-Built/Barebones PCs
· Networking
· Peripherals
· General Hardware
· Highly Technical
· Computer Help
· Home Theater PCs
· Consumer Electronics
· Digital and Video Cameras
· Mobile Devices & Gadgets
· Audio/Video & Home Theater
· Software
· Software for Windows
· All Things Apple
· *nix Software
· Operating Systems
· Programming
· PC Gaming
· Console Gaming
· Distributed Computing
· Security
· Social
· Off Topic
· Politics and News
· Discussion Club
· Love and Relationships
· The Garage
· Health and Fitness
· Home and Garden
· Merchandise and Shopping
· For Sale/Trade
· Hot Deals with Free Stuff/Contests
· Black Friday 2015
· Forum Issues
· Technical Forum Issues
· Personal Forum Issues
· Suggestion Box
· Moderator Resources
· Moderator Discussions

Thread Tools
Old 11-01-2012, 02:28 AM   #1
Junior Member
Join Date: Nov 2012
Posts: 2
Default Outlook VBA script to save file with subject as filename

Good day. New member here

Long story short:
I would like a script that grabs the attachments from a incoming mails and saves them in a specified folder with the subject as the filename.

The bigger picture:
I regularly recieve mails with attached pdf files. The pdf filename is always called "Vedlegg" ("attachement" in norwegian) and the subject field is always "ARBEIDSORDRE 589492/2012 ,VH35682 ,FORHÅNDSVIS" except for the numbers being different each time. I work in a car workshop and these pdf's are work-orders containing a description of what to repair on the different cars. Thus the numbers will be different on each mail, but I want them to be automatically stored with the subject field as the filename.

Also, I am aware that "/" can not be used in filenames. So I would like something that inserts a space instead and also maybe deletes the first and last word "ARBEIDSORDRE" and "FORHÅNDSVIS" as those are of no interest when I later want to search for it.

Kind Regards

Last edited by Xyseven; 11-01-2012 at 02:34 AM.
Xyseven is offline   Reply With Quote
Old 11-03-2012, 01:03 PM   #2
Ken g6
Elite Member
Ken g6's Avatar
Join Date: Dec 1999
Location: 🌲 Colorado 🌲
Posts: 11,233

OK, so what programming languages do you know that might have a POP3 or IMAP library?

Edit: I always miss the title.
Look for really BIG primes with TeAm AnandTech PrimeGrid!
Next race: June 20-25
Curse your sudden but inevitable betrayal, Intel!

Last edited by Ken g6; 11-03-2012 at 01:34 PM.
Ken g6 is online now   Reply With Quote
Old 11-03-2012, 03:25 PM   #3
Diamond Member
coloumb's Avatar
Join Date: Oct 1999
Location: Northwest
Posts: 4,098

You might want to try here as well [seems to be a bit more active community]:


I don't think it would be too difficult to program...
This sounds like fun. I will enjoy "bending" her to my will...
coloumb is offline   Reply With Quote
Old 11-05-2012, 05:05 AM   #4
Junior Member
Join Date: Nov 2012
Posts: 2

Thank you for the quick reply. I have no knowledge of VBA or any programming at all. My job is with automobilenetworking and hardware But I will try that forum you linked - thanks!

I am using this today (which does almost what I want):

Sub SaveAllAttachments(objitem As MailItem)

Dim objAttachments As Outlook.Attachments
Dim strName, strLocation As String
Dim dblCount, dblLoop As Double
strLocation = "KNy mappe struktur\Servicemarked\Volkswagen og Audi verksted\Gjennomganger - Teksteark\Jack\"

On Error GoTo ExitSub
If objitem.Class = olMail Then
Set objAttachments = objitem.Attachments
dblCount = objAttachments.Count
If dblCount <= 0 Then
GoTo 100
End If
For dblLoop = 1 To dblCount
strID = " from " & Format(Date, "mm-dd-yy")
strName = objAttachments.Item(dblLoop).Filename 'Get attachment name
strExt = Right$(strName, 4) 'Store file Extension
strName = Left$(strName, Len(strName) - 4) 'Remove file Extension
strName = strName & strID & strExt 'Reattach Extension
strName = strLocation & strName
objAttachments.Item(dblLoop).SaveAsFile strName
Next dblLoop
End If
Set objAttachments = Nothing
Set objOutlook = Nothing

End Sub
Xyseven is offline   Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

All times are GMT -5. The time now is 10:40 PM.

Powered by vBulletin® Version 3.8.8 Alpha 1
Copyright ©2000 - 2016, vBulletin Solutions, Inc.