VBA根据具有值的行数在电子邮件的HTMLBody内生成行
所以我收到了一个对语句进行排序的请求,我有一个宏可以自动对语句进行排序,但现在我希望在最后用同一个宏发送电子邮件。我是在70%的解决方案,但我被困在一个关键的部分。我没有一个固定的数字或声明,每天订购的一些天,它的2,它的20 问题:如何根据具有值的行数在电子邮件正文中生成一行文本 以下是我到目前为止的情况:VBA根据具有值的行数在电子邮件的HTMLBody内生成行,vba,excel,Vba,Excel,所以我收到了一个对语句进行排序的请求,我有一个宏可以自动对语句进行排序,但现在我希望在最后用同一个宏发送电子邮件。我是在70%的解决方案,但我被困在一个关键的部分。我没有一个固定的数字或声明,每天订购的一些天,它的2,它的20 问题:如何根据具有值的行数在电子邮件正文中生成一行文本 以下是我到目前为止的情况: Sub Email() Dim OutApp As Object Dim OutMail As Object Dim Email As String Dim
Sub Email()
Dim OutApp As Object
Dim OutMail As Object
Dim Email As String
Dim ws As Worksheet
Set ws = Worksheets("Data")
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
K = 2
Do While ws.Cells(K, 1) <> "" ' While column A has cells with data do
' this matches 'Name Of' & cell value and puts it in column E (E1=Name of Joe)
ws.Cells(K, 5) = "Name Of " & ws.Cells(K, 1).Value
K = K + 1
Loop
Email = "Hello, <br><br>" & _
"The following Statements were ordered today: <br><br>" & _
'===================================================================
"<br>" & ws.Cells(k, 5).Value & _
' I am trying to get this line to be generated depending on how many
' rows have data in column A so if there are 5 names there are 5 lines
'==================================================================
"<br><br> Thank you." & _
"<br><br><br> <i> Call if you have any questions </i>"
With OutMail
.to = "me@me.com"
.CC = ""
.BCC = ""
.Subject = "Statements Ordered"
.HTMLBody = Email
.Send
End With
Set OutMail = Nothing
Set OutApp = Nothing
End Sub
我要做的是让VBA查看A列,看看有多少行包含数据,这将生成单元格的行名和值
我还向代码中添加了注释。这将遍历第5列中的所有内容,并将所有数据放入变量“myvalue”中 这应该足以让你开始
btm = ws.Cells(Rows.Count, 5).End(xlUp).Row
for i = 1 to btm
myvalue = myvalue & "<br>" & ws.Cells(i, 5).Value
next i
Email = "Hello, <br><br>" & _
"The following Statements were ordered today: <br><br>" & _
"<br>" & myvalue & _
"<br><br> Thank you." & _
"<br><br><br> <i> Call if you have any questions </i>"
btm=ws.Cells(Rows.Count,5).End(xlUp).Row
对于i=1至btm
myvalue=myvalue&“
”&ws.Cells(i,5).Value
接下来我
Email=“你好,
”&_
“今天订购了以下声明:
”&_
“
”&myvalue&_
“
谢谢你。”_
“
如果有任何问题,请致电”
我对您的要求有点困惑,k-2的值是您想要打印的数字吗?我更新并添加了评论,希望这有助于您提出问题,我正在努力一起解决这个问题
btm = ws.Cells(Rows.Count, 5).End(xlUp).Row
for i = 1 to btm
myvalue = myvalue & "<br>" & ws.Cells(i, 5).Value
next i
Email = "Hello, <br><br>" & _
"The following Statements were ordered today: <br><br>" & _
"<br>" & myvalue & _
"<br><br> Thank you." & _
"<br><br><br> <i> Call if you have any questions </i>"