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:

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




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

The Tectonic Speed of Government, Part 4: Momentum This “Tectonic Speed” series is about why Government IT Projects take such a long time. The name refers to tectonic plates, rubbing against each other. No visible movement for a while then… CRACK! Government change is like that; it can take a long time to build, but when it happens it can be intense.  For more on that here is my 20:50 speech on this theme from the Code for America Summit 2020 , which turned into a virtual event. (I can tell you that it’s 20:50 because of the PechaKucha-ish format: 25 slides for 50 seconds each.) ************************************************************************** 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. ************************************************************************** One impact of the COVID-19 pandemic is a shake-up of p

But First... Let Me Take a Selfie

Excel 3D Map of my drives home. Colors are waypoints and height is the trip duration. Read on to see what the hell this is. This piece began before the pandemic, but the use of our phones as tracking devices for contact tracing prompts tough questions about privacy and tracking that make this timelier than I expected. See the middle section for thoughts on this. *********************************************************************************************** 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. *********************************************************************************************** “OK Google… Track Me All Day Long”  Google Location History logs your every move, every day – if you turn it on. (To their credit, it’s off by default.) It’s worth asking - why would anyone want to do this?  Well, I did it for a few years because I was curious about the r

Why the Tectonic Speed of Government?

The original name ("Glacial Speed of Government”) is both cliché and inaccurate, as it implies a faster pace than it used to. I decided that “Tectonic Speed” is more accurate because change in government shows tremendous resistance and moves slowly, but when it happens progress can occur in significant outbursts - and in those moments, there is great opportunity!     Click on "Read the Whole Thing" to access these links: Part 1 |  Part 2   |  Part 3  | Part 4 | Wait there's a Video?!  

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