我在Excel中有电子邮件注册。我需要创建命令按钮以打开包含最后一行详细信息的新电子邮件。即最后一行,列C,列F.请注意,以前发送的电子邮件中存在数百行。如何为该命令按钮编写代码。
提前致谢
Hewage
答案 0 :(得分:1)
*适用于以下
Private Sub CommandButton22_Click()
Dim a As Integer
Dim objOutlook As Object
Dim objMail As Object
Dim rngTo As Range
Dim rngSubject As Range
Dim rngBody As Range
Dim rngAttach As Range
Set objOutlook = CreateObject("Outlook.Application")
Set objMail = objOutlook.CreateItem(0)
a = ActiveCell.Row
With ActiveSheet
Set rngTo = .Cells(a, "C")
Set rngSubject = .Cells(a, "E")
'Set rngBody = .Range("B3")
'Set rngAttach = .Range("B4")
End With
With objMail
.To = rngTo.Value
.Subject = rngSubject.Value
'.Body = rngBody.Value
'.Attachments.Add rngAttach.Value
.Display 'Instead of .Display, you can use .Send to send the email _
or .Save to save a copy in the drafts folder
End With
Set objOutlook = Nothing
Set objMail = Nothing
Set rngTo = Nothing
Set rngSubject = Nothing
Set rngBody = Nothing
Set rngAttach = Nothing
End Sub
此致 Hewage
答案 1 :(得分:0)
set wbNew = application.workbooks.add
set wsNew = wbNew.sheets(1)
thisworkbook.rows(intLastRow).copy wsNew.rows(1)
wbnew.sendmail(stRecipients)
那样的东西?
或者您是说最后一行包含您要发送电子邮件的详细信息? “sendmail”使您能够指定收件人和主题,但您可能希望查看Outlook对象(通过工具/参考添加),然后您可以执行以下操作:
Set apOutlook = CreateObject("Outlook.Application")
apOutlook.Session.Logon
Set itEmail = apOutlook.CreateItem(olMailItem)
With itEmail
.To = stRecipient
.Subject = stSubject
.Body = stBody
.Display
End With
即。添加指定“正文”的功能,并弹出一个Outlook电子邮件对象而不是难看的“应用程序试图代表您发送电子邮件”窗口,SendMail会这样做...