在VBA / Excel中进行编码以将工作簿作为附件发送到电子邮件中

时间:2019-05-02 19:57:09

标签: excel vba email lotus-notes

我有一个excel工作簿,其中包含一个供用户填写信息的简单表格。 在工作簿中,有一个按钮可以根据表单中的信息在Lotus Notes中创建电子邮件,并定义主题和收件人。 我想补充的是完整的工作簿,作为所创建电子邮件的附件。

我尝试使用https://www.rondebruin.nl/win/s1/notes/notes.htm所示的一些解决方案,但无法正常工作。

这是我当前拥有的代码:

Sub SendEMail(Subj As String)
    Dim Email As String
    Dim Msg As String, URL As String
    Dim r As Integer, x As Double
    Email = Cells(5, 3)
    Subj = Application.WorksheetFunction.Substitute(Subj, " ", "%20")
    Msg = Application.WorksheetFunction.Substitute(Msg, " ", "%20")
    Msg = Application.WorksheetFunction.Substitute(Msg, vbCrLf, "%0D%0A")
    '     Create the URL
    URL = "mailto:" & Email & "?subject=" & Subj & "&body=" & Msg
    '     Execute the URL (start the email client)
    ShellExecute 0&, vbNullString, URL, vbNullString, vbNullString, vbNormalFocus
    '       Wait two seconds before sending keystrokes
    'Application.Wait (Now + TimeValue("0:00:02"))
    'Application.SendKeys "%s"
    'Next r
End Sub

Sub generate_email()
    Dim Subject As String, ActiveRow As Long

    On Error GoTo CatchError
    ActiveRow = ActiveCell.Row

    Subject = "Requestor: " & Cells(4, 3) & " - Location: " & _
              Cells(4, 8) & " - Department: " & Cells(5, 8) & _
              " - Supplier: " & Cells(8, 3) & ""

    SendEMail Subject
    Exit Sub

CatchError:
    MsgBox "Error, send email manually:" & vbCrLf & Err.Description, _
           vbExclamation, "Error, send email manually"
End Sub

我想知道我应该添加什么代码,以便将完整的工作簿添加为所创建电子邮件的附件。

0 个答案:

没有答案