0

I was trying to save my current email to a folder.

I modified my code a bit. However, there is an error.

*438 : object doesn't support this property or method.*

on this code:

GetCurrentItem().SaveAsFile StrFile, olMSG

My VBA code:

Public fso As New FileSystemObject
Public objApp As Outlook.Application
Public OutMail As Outlook.MailItem
Public strPath As String
Public StrFile As String

Function GetCurrentItem() As Object

    Set objApp = CreateObject("Outlook.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


Sub saveMyEmail()

      strPath = "C:\Users\admin\Desktop\my vba\fso\"


      StrFile = strPath & Worksheets("Main").Range("A1").Value & ".msg"
      GetCurrentItem().SaveAsFile StrFile, olMSG



Set fso = Nothing

End Sub
Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
pexpex223
  • 371
  • 4
  • 10
  • 25

1 Answers1

0

If you run the code in the Outlook VBA environment:

Set myItem = Application.ActiveInspector

You need to set the objApp object to the instance of the Application class or use the global Application property in Outlook VBA.

Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45