Code Red > VB(A)
Outlook VBA (365) vs 2010
(1/1)
David Hall:
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: ---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
Next
End If
Set fd = Nothing
xlApp.Quit
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
--- End code ---
cmwade77:
I unfortunately don't know the answer to this, but very handy little routine.
kirby:
Hi
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 www.slipstick.com 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...
Navigation
[0] Message Index
Go to full version