vb.net - VB.net - 从共享文件夹中读取 .msg 文件并提取其中的附件
问题描述
我对 VB 完全陌生,我正在尝试使用以下代码提取保存在 .msg 文件中的附件。如果这是正确的方法,有人可以帮助我吗?
我面临以下编译器错误。有人可以帮我解决这个问题吗?
- Outlook.Attachment 未定义。
- End Sub'必须以匹配的'Sub'开头
- 对非共享成员的引用需要对象引用。
- 语句不能出现在方法主体中。假定方法结束
- 方法参数必须用括号括起来。
- 未定义类型“Outlook.MailItem”。
Sub SaveOlAttachments()
Dim msg As Outlook.MailItem
Dim att As Outlook.Attachment
Dim strFilePath As String
Dim strAttPath As String
Dim strFile As String
strFilePath = "C:\Users\...\Desktop\Test\"
strAttPath = "C:\Users\...\extracted attachment\"
strFile = Dir(strFilePath & "<Doc Name>.msg")
Do While Len(strFile) > 0
msg = Application.CreateItemFromTemplate(strFilePath & strFile)
If msg.Attachments.Count > 0 Then
For Each att In msg.Attachments
att.SaveAsFile strAttPath & att.FileName
Next
End If
strFile = Dir
Loop
End Sub
解决方案
CreateItemFromTemplate
您可以使用Namespace.OpenSharedItem
打开 MSG 文件,而不是使用。
您还需要将 Outlook 添加到您的 VB.Net 项目引用中。
推荐阅读
- vuejs3 - 你需要为 vue3 中的反应对象发出事件吗?
- azure-devops - 在 Azure DevOps 中,如何安排发布管道以按季度执行?
- python - 尝试在 Tensorflow 上使用 .h5 加载的分类模型进行预测,返回 IndexError: list index out of range
- firebase - Firestore 错误:[cloud_firestore/unknown] 无效参数(dartObject):无法转换:“_FieldValueServerTimestamp”实例
- mongodb - MongoDB - 无法调用 ClusterDescription.getConnectionMode(),因为 clusterDescription 为空
- reactjs - 解决纱线工作区中的 TypeScript 依赖项
- javascript - Javascript更改具有特定ID的所有跨度的颜色
- apache-spark - 为什么创建了 5 个分区和 10 个桶后,后端创建的数据文件数量如此之多?
- docker - 在 Docker Desktop 中启用 k8s 实验功能
- python - 如何在 Python 中检查新设备何时连接到 Wifi