Skip to main content

Outlook Macro to Save e-Mail Files

Outlook Macro to Save e-Mail Files

For background to this, see the section on e-mail in this post: https://blog.tectonicspeed.com/2017/09/personal-archiving-get-your-shit.html

ub SaveMails()


 Const OLTXT = 0

  Dim currentExplorer As Explorer

  Dim Selection As Selection

  Dim oMail As Outlook.MailItem

  Dim obj As Object

  Dim sPath As String

  Dim dtDate As Date

  Dim sName As String

  Dim rName As String

  Dim fName As String

  Dim feName As String

  

  Set currentExplorer = Application.ActiveExplorer

    Set Selection = currentExplorer.Selection


 For Each obj In Selection

  Set oMail = obj

  sName = oMail.Subject

  rName = oMail.ReceivedByName

  fName = oMail.SenderName

  feName = oMail.SenderEmailAddress

  

  ReplaceCharsForFileName sName, "_"

 

  dtDate = oMail.ReceivedTime

  sName = sName & "-" & Format(dtDate, "yyyymmdd", vbUseSystemDayOfWeek, _

    vbUseSystem) & Format(dtDate, "-hhnnss", _

    vbUseSystemDayOfWeek, vbUseSystem) & "-to " & rName & "-from " & feName & ".txt"

  

  oMail.SaveAs "C:\Users\Sanford\OutlookSaves\" & sName, OLTXT

  

  Next

 

End Sub

 

Private Sub ReplaceCharsForFileName(sName As String, _

  sChr As String _

)

  sName = Replace(sName, "/", sChr)

  sName = Replace(sName, "\", sChr)

  sName = Replace(sName, ":", sChr)

  sName = Replace(sName, "?", sChr)

  sName = Replace(sName, Chr(34), sChr)

  sName = Replace(sName, "<", sChr)

  sName = Replace(sName, ">", sChr)

  sName = Replace(sName, "|", sChr)


End Sub

Popular posts from this blog

The Tectonic Speed of Government, Part 1: Procurement

This post is my reaction to conversations about how hard it is to create change in government, and how government projects (and IT projects in particular) take so long from genesis to completion. This is part 1, about procurement; part 2 will address project implementations . PS - there was a surprise Part 3 of this series later! Warning : what follows is an “inside baseball” discussion of government IT procurement. I’m not trying to dissuade you from reading it, but if you’re not enmeshed in this world you might want to consider reading my articles on lighter topics like organizing your electronic life , the greatness of Abbey Road , or the story behind The Room . If you ARE enmeshed in this topic, then please don’t overlook my call to action at the end! Changing the process will take a group effort, and I’m hoping to get feedback on my scheme to create a library of reusable software specifications. By the way, this post’s first title was “The Glacial Speed of Government” bu

How To Videos: Lucity Queries with Microsoft SQL Server and Excel

What follows is not a blog, but some suggestions on using Microsoft SQL Server "Views" to query your Lucity data using Excel.   This information is intended to assist Lucity software users, and not for any nefarious purposes. I recommend watching the videos in Full Screen view and with HD resolution.  They're not as blurry as they look on this page!!  Each of these about two minutes long, but the original actions only took 50 seconds each.  (After recording them, I decided to slow them down to make them more watchable.) 1. How to create a SQL Server "View".   The video shows how to create a new View from the core Work Order table.  (WKORDER - see the data dictionary here .)  The video first shows the simple method of creating a view with all fields, then shows the more effective method of including only needed fields, and re-labeling them with their on-screen names. Music: "A View to a Kill" - Duran Duran 2. How to Connect to the Vi

Why the Tectonic Speed of Government?

The original name was "The Glacial Speed of Government” but that title is both cliché and inaccurate, as today it implies a faster pace than it used to. I decided that “Tectonic Speed” is more accurate because you can push very hard, but change in government shows tremendous resistance.  However, when change happens it can occur in significant outbursts - and in those moments, there is great opportunity! Part 1 |  Part 2   |  Part 3  | Part 4 | Wait there's a Video?!  

Tectonic Speed of Government, Part 2: Why do Government IT Projects Take So Long?

This is part two of my series on why government IT projects take so long. Part one complained that the Purchasing process is tough to navigate because methodically describing what you want to buy - and documenting your decision making - takes effort. That blog helped me vent some frustrations about parts of my job, although I admit that it was a little dry. (But please, this is Government Procurement.) With part two I’m on my home turf: the process that starts with the purchase of an IT tool and ends with its everyday use by people. If the process was successful, users are doing their jobs better than they did before. (A less successful outcome that also occurs: it’s harder to do their jobs, but at least their managers have better data.) This process, which I’ll refer to as the “Implementation” or “Project,” can take months or years for any organization - let alone a government. My first section explains why government IT projects take a long time, while the other three suggest

The Tectonic Speed of Government, Part 3: It’s Never Over

Recently, I wrote two posts discussing why IT Projects take a long time: one on the Procurement Process and one about Project Implementations .  They were written during a time of three simultaneous projects, and they were therapy for me to exorcise some complaints... and make suggestions for others. From the start, I planned those as two topics – and I thought they'd finish the series. But this third part was a surprise, and the greatest lesson I learned from those projects. ********************************************************************************************* Disclaimer: All of the ideas expressed in this article are my personal statements and opinions, and do not reflect the opinions/statements of the City of Urbana. ********************************************************************************************* “It ain’t over till it’s over” - Yogi Berra on baseball, not IT projects. Trick Question : When is a software project over? Answer : Never