Author Topic: Outlook VBA (365) vs 2010  (Read 5122 times)

0 Members and 1 Guest are viewing this topic.

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4075
Outlook VBA (365) vs 2010
« on: November 06, 2018, 11:35:10 AM »

I have developed a short macro that allows my 365 users to save email out to the project folders.  I have 2 users that are still on 2010, and I can not figure out why the code wont work.  I thought it was a reference or something just as easy, but no luck.  Here is the code if anyone has an idea
Code: [Select]
Sub SaveACopy() 'ByVal Item As Object)  'Item As Object
    Const olMsg As Long = 3
    Dim m As MailItem
    Dim strPath As String
     Set m = GetCurrentItem
    If TypeName(m) <> "MailItem" Then Exit Sub
Dim xlApp As Object
Set xlApp = CreateObject("Excel.Application")
    xlApp.Visible = False
Dim fd As Office.FileDialog
Set fd = xlApp.Application.FileDialog(msoFileDialogFolderPicker)
Dim selectedItem As Variant
If fd.Show = -1 Then
    For Each selectedItem In fd.SelectedItems
        Debug.Print selectedItem
        strPath = selectedItem
End If
Set fd = Nothing
Set xlApp = Nothing
Dim strSubject As String
strSubject = m.Subject
strSubject = Replace(strSubject, ":", "")
'strPath = """" & strPath
strPath = strPath & "\" & strSubject
strPath = strPath & " " & Format(Now(), "ddmmmyyyy-hhNNss") '"yyyy-mm-dd-hhnnss"    YYYY-mm-dd
strPath = strPath & ".msg"
strPath = strPath '& """"
m.SaveAs strPath, olMsg
m.Close olDiscard
End Sub
'Set objItem = objApp.ActiveExplorer.Selection.Item(1)
Function GetCurrentItem() As Object
    Dim objApp As Outlook.Application 
    Set objApp = Application
    On Error Resume Next
    Select Case TypeName(objApp.ActiveWindow)
        Case "Explorer"
            Set GetCurrentItem = objApp.ActiveExplorer.Selection.Item(1)
        Case "Inspector"
            Set GetCurrentItem = objApp.ActiveInspector.CurrentItem
    End Select
    Set objApp = Nothing
End Function
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)


  • Swamp Rat
  • Posts: 1443
Re: Outlook VBA (365) vs 2010
« Reply #1 on: November 06, 2018, 07:52:47 PM »
I unfortunately don't know the answer to this, but very handy little routine.


  • Newt
  • Posts: 127
Re: Outlook VBA (365) vs 2010
« Reply #2 on: November 09, 2018, 12:52:29 PM »

We don't have Outlook 2010 anymore, so cannot check.

I use a similar routine to save messages or write pdfs with an ISO 8601 date-time code (YYYY-MM-DD_Thhnn), mostly cribbed from code snippets.  These were ported from 2007 through 2010, 2013 to 365 with no changes. 

One persistent problem is exceeding Windows 255 character path and filename length (especially when saving to our already too long network project folders into deeply nested subfolders).  Simple fix if you don't mind truncating the message filename.

Maybe check if App 'Inspector' is valid in 2010.

Not very helpful, sorry...