简体   繁体   English

VBA Outlook - 另存为电子邮件

[英]VBA outlook - save as email

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:我的 VBA 代码:

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

If you run the code in the Outlook VBA environment:如果在 Outlook VBA 环境中运行代码:

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.您需要将 objApp 对象设置为 Application 类的实例或使用 Outlook VBA 中的全局 Application 属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM