通过 MS Access 将选定的 Outlook 电子邮件另存为 .msg 文件 VBA
Save Selected Outlook Email Message as .msg File via MS Access VBA
我设法将此代码获取到 select 并通过 MS Access 将 Outlook 电子邮件保存到我电脑上的文件夹中。
https://social.msdn.microsoft.com/Forums/en-US/edf1d135-ffd3-4b3a-8318-db7f86047872/save-a-selected-outlookmail-as-msgfile-with-vba-in-access?forum=outlookdev
Option Compare Database
Option Explicit
Private Const SavePath As String = "D:\New folder\"
Sub SaveSelectMail()
Dim olApp As Outlook.Application
Dim olExplorer As Outlook.Explorer
Dim olMail As Outlook.MailItem
Set olApp = New Outlook.Application
Set olExplorer = olApp.ActiveExplorer
Set olMail = olExplorer.Selection(1)
olMail.SaveAs SavePath, OlSaveAsType.olMSG
Set olMail = Nothing
Set olExplorer = Nothing
Set olApp = Nothing
End Sub
我在 Access 中创建了一个带有命令按钮的表单,代码如下(在单击事件时):
Private Sub Command6_Click()
Call SaveSelectMail
End Sub
当我点击按钮时弹出以下错误(Outlook 已打开):
Run-time error '-2147352567 (80020009)':
Cannot write to D:\New Folder. Right-click the folder that contains the file you want to write to, and then click properties on the shortcut menu to check your permission for the folder.
我检查了文件夹属性,但不知道该怎么做。
我试图在我的便携式硬盘上设置一个文件夹的路径。弹出相同的错误。
将假设您有一个实际存在的文件夹路径来代替 "D:\New Folder\"
。
路径参数中必须包含保存文件的名称。 SavePath & "somefilename.msg"
.
如果您希望文件名是动态的,连接变量,选项:
用户在表单文本框中输入:SavePath & Me.tbxFile & ".msg"
根据电子邮件的属性构建
我设法将此代码获取到 select 并通过 MS Access 将 Outlook 电子邮件保存到我电脑上的文件夹中。
https://social.msdn.microsoft.com/Forums/en-US/edf1d135-ffd3-4b3a-8318-db7f86047872/save-a-selected-outlookmail-as-msgfile-with-vba-in-access?forum=outlookdev
Option Compare Database
Option Explicit
Private Const SavePath As String = "D:\New folder\"
Sub SaveSelectMail()
Dim olApp As Outlook.Application
Dim olExplorer As Outlook.Explorer
Dim olMail As Outlook.MailItem
Set olApp = New Outlook.Application
Set olExplorer = olApp.ActiveExplorer
Set olMail = olExplorer.Selection(1)
olMail.SaveAs SavePath, OlSaveAsType.olMSG
Set olMail = Nothing
Set olExplorer = Nothing
Set olApp = Nothing
End Sub
我在 Access 中创建了一个带有命令按钮的表单,代码如下(在单击事件时):
Private Sub Command6_Click()
Call SaveSelectMail
End Sub
当我点击按钮时弹出以下错误(Outlook 已打开):
Run-time error '-2147352567 (80020009)': Cannot write to D:\New Folder. Right-click the folder that contains the file you want to write to, and then click properties on the shortcut menu to check your permission for the folder.
我检查了文件夹属性,但不知道该怎么做。
我试图在我的便携式硬盘上设置一个文件夹的路径。弹出相同的错误。
将假设您有一个实际存在的文件夹路径来代替 "D:\New Folder\"
。
路径参数中必须包含保存文件的名称。 SavePath & "somefilename.msg"
.
如果您希望文件名是动态的,连接变量,选项:
用户在表单文本框中输入:
SavePath & Me.tbxFile & ".msg"
根据电子邮件的属性构建