从工作表和打开的Outlook复制选择范围,并将复制的内容粘贴到新电子邮件中

时间:2015-03-12 09:06:44

标签: vba excel-vba excel

有人可以告诉我需要放入什么类型的BodyFormat(olFormat ...) 以及如何申报 a =范围(“A1:G”& r)。复制 然后把什么放在电子邮件的正文

我不希望它将其复制为HTML。

谢谢!

编辑:这是我的代码

Sub Button()
 Dim str As String
 Set OutApp = CreateObject("Outlook.application")
 Set OutMail = OutApp.CreateItem(olMailItem)
 Dim EmailBodyTotal As String
 name_work = ActiveSheet.Name
 daytime = Right(name_work, 2)
 With OutMail
   .To = ""
   .cc = ""
    .bcc = ""
    .Subject = "" 
    .Body = Range("A1:G" & r )
    .Display
 End With

 Set OutMail = Nothing
 Set OutApp = Nothing
End Sub

1 个答案:

答案 0 :(得分:1)

以下内容将生成一个纯文本电子邮件,其中您的单元格引用作为电子邮件正文并显示电子邮件消息窗口。您可以跳过该部分,并取消注释.send行;这将直接发送您的电子邮件。

Sub sendMail()
Dim olApp As Outlook.Application
Dim olMail As Outlook.MailItem
Dim strEmailTo As String
Dim olNs As Outlook.Namespace
Set olApp = New Outlook.Application
Set olMail = olApp.CreateItem(olMailItem)
Set olNs = olApp.GetNamespace("MAPI") 'as appropriate
olNs.Logon
strEmailTo = "" 'insert email address(es) here
With olMail
    .To = strEmailTo
    .subject = ""   'email subject goes here
    .Body = Range("A1:G" & r)   'or put the values in a string variable
    .Display
   '.Send
End With
End Sub