gpt4 book ai didi

excel - 根据主题使用vba下载outlook附件在其他计算机上不起作用

转载 作者:行者123 更新时间:2023-12-04 20:48:46 44 4
gpt4 key购买 nike

该代码从 Excel 中的“A”列中读取行,在 Outlook 中查找它们并将附件下载到范围(“E3”)中的文件夹,该文件夹会根据计算机而变化。
但是,在我的电脑上它运行良好,在我同事的电脑上它不下载文件。

Sub Descarga()
Dim it, at As Variant, t As Long
Dim olApp As Outlook.Application
Dim olNS As Outlook.Namespace
Dim olFolder As Outlook.MAPIFolder
Dim olItem As Object
Dim mailitem As Outlook.mailitem
Dim olAtt As Outlook.Attachment

Set olApp = New Outlook.Application
Set olNS = olApp.GetNamespace("MAPI")
Set olFolder = olNS.GetDefaultFolder(olFolderInbox)

For Each it In CreateObject("outlook.application").GetNamespace("MAPI").GetDefaultFolder(6).Items
For t = 1 To Range("A" & Rows.Count).End(xlUp).Row
If InStr(it.Subject, Cells(t, 1)) Then
For Each at In it.Attachments
at.SaveAsFile (Range("E3")) & "\" & at.DisplayName 'Range("E3") is the path
Next
End If
Next
Next

End Sub

最佳答案

首先,不要使用at.DisplayName - 使用 at.FileName .
其次,保存前检查附件类型——OOM不会让你保存附件,例如嵌入的OLE对象,你需要先检查附件类型。

For Each at In it.Attachments
if at.Type = 1 Then 'olByValue
at.SaveAsFile (Range("E3")) & "\" & at.FileName 'Range("E3") is the path
End If
Next

关于excel - 根据主题使用vba下载outlook附件在其他计算机上不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71238288/

44 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com