Macros 不作为附件的电子邮件访问报告的宏

Macros 不作为附件的电子邮件访问报告的宏,macros,ms-access-2007,Macros,Ms Access 2007,我不知道VBA。有没有办法让宏将报告发送到电子邮件正文中而不是作为附件的位置?我目前使用“send object”命令并以html格式发送它。如果您使用Outlook,您可以在磁盘上编写报告或查询并使用HTMLBody或RTFBody,我已经测试了一段时间,希望它仍然有用 Const ForReading = 1, ForWriting = 2, ForAppending = 3 Dim fs, f Dim RTFBody Dim MyApp As New Outlook.Applicatio

我不知道VBA。有没有办法让宏将报告发送到电子邮件正文中而不是作为附件的位置?我目前使用“send object”命令并以html格式发送它。

如果您使用Outlook,您可以在磁盘上编写报告或查询并使用HTMLBody或RTFBody,我已经测试了一段时间,希望它仍然有用

Const ForReading = 1, ForWriting = 2, ForAppending = 3

Dim fs, f
Dim RTFBody
Dim MyApp As New Outlook.Application
Dim MyItem As Outlook.MailItem

DoCmd.OutputTo acOutputReport, "Report1", acFormatRTF, "Report1.rtf"
''DoCmd.OutputTo acOutputQuery, "Query1", acFormatHTML, "Query1.htm"

Set fs = CreateObject("Scripting.FileSystemObject")

Set f = fs.OpenTextFile("Report1.rtf", ForReading)
''Set f = fs.OpenTextFile("Query1.htm", ForReading)
RTFBody = f.ReadAll
''Debug.Print RTFBody
f.Close

Set MyItem = MyApp.CreateItem(olMailItem)
With MyItem
   .To = "abc@def.ghi"
   .Subject = "Subject"
   .RTFBody = RTFBody
   ''.HTMLBody = RTFBody
End With
MyItem.Display

我使用SendObject就是这样做的,它将报告附加为RTF并将其放入电子邮件正文中

Private Sub btnEmail_Click()

    Dim IDnumber As Integer
    Dim Message As String
    Dim EmailTo As String
    Dim FileName As String

    'Get the current record's ID Number
    IDnumber = Me![ID]
    'set file name and path
    FileName = Environ("USERPROFILE") & "\My Documents\temp.html"
    'set email address
    EmailTo = "someone@domain.com"

    'get form to open a new record
    DoCmd.GoToRecord , , acNewRec

    'generate report for the current record entered
    DoCmd.OpenReport "ReportName", acPreview, , "[ID]=" & IDnumber, acHidden
    'create HTML file for the report
    DoCmd.OutputTo acOutputReport, "ReportName", acFormatHTML, FileName

    'open file
    Open FileName For Input As #1
    'read the file into a string
    Message = Input(LOF(1) - 1, 1)
    'close the file
    Close 1

    'generate email
    DoCmd.SendObject acSendReport, "ReportName", acFormatRTF, EmailTo, , , "Subject", Message
    'close the report
    DoCmd.Close acReport, "ReportName"

    'suppress errors if file is not there
    On Error Resume Next
    'remove file
    Kill FileName

End Sub