将电子邮件中的附件保存到硬盘VBA ms访问权限

时间:2019-02-05 21:12:41

标签: access-vba

您好,我想在Acces女士的按钮上编写一个OnClick函数,以保存电子邮件中的附件。

我找到了这段代码,但是它只能作为Outlook中的宏而不在访问中工作。 我收到此错误“远程服务器计算机不存在或不可用”

Option Compare Database

Private Sub Polecenie1_Click()    

Dim olSelection As Selection
Dim olMail As Object
Dim olAttachments As Attachments
Dim FileCount As Long, i As Long
Dim SaveFolderPath As String

On Error GoTo errHandle
'// Where do you want to save the files?
SaveFolderPath = "d:\odebrane"
Set olSelection = ActiveExplorer.Selection

'----------------------------------------------------
' Extract Attachment(s)
'----------------------------------------------------
'// Here we will iterate each email from our selection
For Each olMail In olSelection

    '// making sure it is an actual Outlook mail only
    If TypeName(olMail) = "MailItem" Then

        Set olAttachments = olMail.Attachments

        FileCount = olAttachments.Count

        If FileCount > 0 Then

            For i = FileCount To 1 Step -1

                '// Save file attachments
                olAttachments.Item(i).SaveAsFile SaveFolderPath & olAttachments.Item(i).FileName

            Next i

        End If

        Set olAttachments = Nothing

    End If
Next olMail
Exit Sub

errHandle:
MsgBox "Error: " & Err.Description, vbExclamation

End Sub

0 个答案:

没有答案