【发布时间】:2014-08-23 14:49:53
【问题描述】:
我有 10 列数据,其中包含不同数量的行,这些数据作为未格式化的范围通过电子邮件发送。我希望能够用空格正确填充每列中的单元格,以便未格式化的范围以均匀间隔复制。范围未格式化的原因是我使用的是 LotusNotes,并且没有像 Outlook 那样的集成选项。无论如何,如果不添加列,我可以用空格字符填充单元格,以便范围在电子邮件中看起来不错?
编辑:所以这允许我通过输入框输入电子邮件并选择一个范围。它将创建电子邮件并发送,但不会保留单元格格式(即间距)可以这样做吗?我曾尝试使用 MIME 实体来使用 HTML,但是我不确定如何将范围复制到 HTML 正文中
更新代码:
Sub Lotus_Email()
Dim noSession As Object, noDatabase As Object, noDocument As Object
Dim vaRecipient As String
Dim rnBody As Range
Dim Data As DataObject
Const stSubject As String = "EMAIL SUBJECT"
Const stMsg As String = "Please review the following Purchase Orders and advise."
Const stPrompt As String = "Please select the range:"
'This is one technique to send an e-mail to many recipients but for larger
'number of recipients it's more convenient to read the recipient-list from
'a range in the workbook.
vaRecipient = InputBox("Please enter an e-mail address", "E-Mail Address Entry")
On Error Resume Next
Set rnBody = Application.InputBox(Prompt:=stPrompt, _
Default:=Selection.Address, Type:=8)
'The user canceled the operation.
If rnBody Is Nothing Then Exit Sub
On Error GoTo 0
'Instantiate Lotus Notes COM's objects.
Set noSession = CreateObject("Notes.NotesSession")
Set noDatabase = noSession.GETDATABASE("", "")
'Make sure Lotus Notes is open and available.
If noDatabase.IsOpen = False Then noDatabase.OPENMAIL
'Create the document for the e-mail.
Set noDocument = noDatabase.CreateDocument
'Copy the selected range into memory.
rnBody.Copy
Set rtItem = noDocument.CreateRichTextItem("Body")
With rtItem
.appendtext ("LINE 1")
.addnewline (2)
.appendtext ("LINE 2")
.addnewline (2)
.addnewline (1)
.appendtext ("Please review and respond to the email noted above")
.appendtext ("TEST")
rnBody.PasteSpecial
End With
'Add data to the mainproperties of the e-mail's document.
With noDocument
.Form = "Memo"
.SendTo = vaRecipient
.Subject = stSubject
'Retrieve the data from the clipboard.
' NON-HTML BODY OFF
' .Body = stMsg & vbCrLf & vbCrLf & vbCrLf & vbCrLf & Data.GetText
.SaveMessageOnSend = True
End With
'Send the e-mail.
With noDocument
.PostedDate = Now()
.Send 0, vaRecipient
End With
'Release objects from memory.
Set noDocument = Nothing
Set noDatabase = Nothing
Set noSession = Nothing
'Activate Excel for the user.
AppActivate "Microsoft Excel"
'Empty the clipboard.
Application.CutCopyMode = False
MsgBox "The e-mail has successfully been created and distributed.", vbInformation
End Sub
【问题讨论】:
-
您是否以 HTML 格式发送电子邮件?如果是这样,您可以将间距添加到单元格边框间距。
-
我不这么认为。我有一个提示框,它选择一个单元格范围(Application.InputBox),然后它成为电子邮件的.Body。 Outlook 可以选择通过 HTML 进行格式化,但 LotusNotes 似乎没有这个
-
Lotus Notes 绝对可以发送 HTML 电子邮件。此外,您可以使用 OLE 将 Microsoft Office 集成到 Lotus Notes。参考ibm.com/developerworks/lotus/library/notes-ole
标签: vba email excel automation