【问题标题】:Attach .jpg screenshot to Outlook mail将 .jpg 屏幕截图附加到 Outlook 邮件
【发布时间】:2017-04-22 16:39:31
【问题描述】:

我创建了一个表单,其中包含一个以 .jpg 格式附加屏幕截图的附件字段。

我正在尝试从表单发送电子邮件。

我想将屏幕截图附加到电子邮件中,(已附加在表单上的那个)。

我尝试使用 .attachment.add me.attachment 字段。这不是在电子邮件中附加任何内容。

我还使用组合框来选择要向其发送电子邮件的人(这与电子邮件地址一起存储在另一个表中)。我无法使用所选个人的电子邮件地址填充电子邮件中的“收件人”框。

【问题讨论】:

标签: vba ms-access outlook


【解决方案1】:

实际上 Access 附件字段不是电子邮件附件。 Access 没有内置电子邮件客户端,因此您必须使用电子邮件客户端库,例如 CDO 或 Outlook 对象库:

Public Function SendEmail(strRecipients As String, strSubject As String, _
       Optional strBody As String, Optional strFilePath As String, _
       Optional strFileExtension As String) As String

    On Error GoTo ProcError

    Dim myObject As Object
    Dim myItem As Object
    Dim strFullPath As String
    Dim strFileName As String
    Dim strAttachPath As Variant
    Dim intAttachments As Integer

    Set myObject = CreateObject("Outlook.Application")
    Set myItem = myObject.CreateItem(0)

    With myItem
        .Subject = strSubject
        .To = strRecipients

        If Len(Trim(strBody)) > 0 Then
            .body = strBody
        End If

        If Len(Trim(strFileExtension)) = 0 Then
            strFileExtension = "*.*"
        End If

        If Len(strFilePath) > 0 Then
            strFullPath = strFilePath & "\" & strFileExtension

            If Len(Trim(strFullPath)) > 0 Then  'An optional path was included
                strFileName = Dir(strFullPath)
                Do Until strFileName = ""
                    intAttachments = intAttachments + 1
                    strAttachPath = (strFilePath & "\" & strFileName)
                    .Attachments.add (strAttachPath)
                    ' Debug.Print strAttachPath
                    strFileName = Dir()
                Loop
            End If
        End If

        .Send
        SendEmail = "Message placed in outbox with " & intAttachments & " file attachment(s)."
    End With

ExitProc:
    Set myItem = Nothing
    Set myObject = Nothing
    Exit Function
ProcError:
    MsgBox "Error " & Err.Number & ": " & Err.Description, _
               vbCritical, "Error in SendMail Function..."
    SendEmail = "A problem was encountered attempting to automate Outlook."
    Resume ExitProc

End Function

使用 Field.SaveToFile 将 Access 附件转储到临时文件。

【讨论】:

    猜你喜欢
    • 2017-07-27
    • 1970-01-01
    • 2019-08-16
    • 1970-01-01
    • 2021-11-13
    • 1970-01-01
    • 2013-04-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多