简体   繁体   English

使用 Outlook 2010 打开 Excel 附件

[英]Open Excel attachment using Outlook 2010

I am trying to open an Excel attachment using an Outlook rule.我正在尝试使用 Outlook 规则打开 Excel 附件。 I am using the below VBA to do this:我正在使用下面的 VBA 来做到这一点:

Public Sub saveAttachtoDisk(itm As Outlook.MailItem)

Dim objAtt As Outlook.Attachment
Dim xlApp As Object
Dim FileName As String

For Each objAtt In itm.Attachments
    If InStr(objAtt.DisplayName, ".xlsx") Then
        FileName = "S:\Projects\" & objAtt
        objAtt.SaveAsFile FileName
        Set xlApp = CreateObject("Excel.Application")
        xlApp.Application.Visible = True
        xlApp.Application.EnableEvents = False
        x1App.Workbooks.Open FileName
    End If

    Set objAtt = Nothing
Next
MsgBox ("DONE")

End Sub 

It opens the Excel application, however on the open filename line, it shuts the Excel application and jumps out of the code.它打开 Excel 应用程序,但是在打开的文件名行上,它关闭 Excel 应用程序并跳出代码。

Also please let me know if I am doing this in an overly complicated way!另外请让我知道我是否以过于复杂的方式执行此操作!

It looks like you pass a wrong filepath to the Open method:看起来您将错误的文件路径传递给 Open 方法:

 FileName = "S:\Projects\" & objAtt

Try to use the DisplayName property of the Attachment class.尝试使用附件类的DisplayName属性。

 FileName = "S:\Projects\" & objAtt.DisplayName

Also make sure that you have sufficient privileges for writing on the S drive and can access it any time.还要确保您有足够的权限在 S 驱动器上进行写入并且可以随时访问它。 Try to specify any local drive.尝试指定任何本地驱动器。

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

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