Excel VBA将空格添加到单元格

Excel VBA将空格添加到单元格,vba,email,excel,automation,Vba,Email,Excel,Automation,我有10列不同行数的数据,这些数据以未格式化的范围通过电子邮件发送。我希望能够用空格右键填充每列中的单元格,使未格式化的区域以均匀间隔复制。该范围未格式化的原因是我正在使用LotusNotes,并且我没有像Outlook那样的集成选项。在不添加列的情况下,我是否可以在单元格中填充空格字符,以便在电子邮件中显示良好的范围 编辑:这样我就可以通过输入框输入电子邮件并选择一个范围。它将创建电子邮件并发送,但不保留单元格格式(即间距),可以这样做吗?我已经尝试使用MIME实体来使用HTML,但是我不确定

我有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

未经测试。也许是这样的

=A1&REPT(" ",25-LEN(A1))

所以在使用LotusNotesMIME之后,我可以导入富文本,但是它不会保留列宽和excel格式。我用范围选择创建了一个临时工作簿,并将其作为附件附加。这似乎是LotusNotes处理此问题的方法。

您是否以HTML格式发送电子邮件?如果是这样的话,你可以在单元格边框上加上空格。我不这么认为。我有一个提示框,它选择一个单元格范围(Application.InputBox),然后它就成为电子邮件的.Body。Outlook有通过HTML格式化的选项,但似乎没有。LotusNotes有这个选项。Lotus Notes肯定可以发送HTML电子邮件。此外,还可以使用OLE将Microsoft Office集成到Lotus Notes中。请参考此操作!但是,我试图避免使用公式的原因是,单元格经常会自动更新新信息,这会覆盖我的公式:(