![](/img/trans.png)
[英]How do i save a text attachment form a specific outlook folder to file. using Excel VBA
[英]I'm trying to write VBA macro in Outlook that will save an email's attachment to a specific folder
尝试在网上搜索并根据搜索结果编写了以下代码。 但得到以下错误。 不知道为什么会收到此错误。 请帮助我。
运行时错误“-2147221233 (8004010f)”:自动化错误
VBA代码:
Sub SaveWklyReports()
Dim ol As Outlook.Application
Dim ns As Outlook.Namespace
Dim fol As Outlook.Folder
Dim p As Object
Dim mi As Outlook.MailItem
Set ol = New Outlook.Application
Set ns = ol.GetNamespace("MAPI")
Set fol = ns.Folders(1).Folders("Test")
For Each p In fol.Items
If p.Class = olMail Then
Set mi = p
Debug.Print mi.SenderName, mi.ReceivedTime
End If
Next p
End Sub
该错误意味着没有像ns.Folders(1).Folders("Test")
这样的文件夹
而不是使用显式索引1
使用正确的文件夹名称,例如
Set fol = ns.Folders(myFolderName).Folders("Test")
在我的情况下, myFolderName
设置为我的主帐户的电子邮件地址或其他人的共享邮件帐户的名称 - 对您而言,这取决于您尝试访问的内容
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.