Excel nge 变暗rng As范围 应用 .EnableEvents=False .ScreenUpdate=False 以 设置sh=图纸(“图纸1”) Set-OutApp=CreateObject(“Outlook.Application”) 对于sh.Columns(“B”).Cells.SpecialCells(xlCellTypeConstants)中的每个单元格 '在每行的C:Z列中输入路径/文件名 设置rng=sh.Cells(cell.Row,1).范围(“C1:Z1”) 如果单元格值像“*@*。?*”和_ Application.WorksheetFunction.CountA(rng)>0则 Set-OutMail=OutApp.CreateItem(0) 发邮件 .to=单元格.Value .Subject=“Testfile” .Body=“Hi”&单元格偏移量(0,-1).Value 对于rng.SpecialCells中的每个文件单元(xlCellTypeConstants) 如果修剪(文件单元)”,则 如果Dir(FileCell.Value)“,则 .Attachments.Add FileCell.Value 如果结束 如果结束 下一个文件单元 .Send'或use.Display 以 发送邮件=无 如果结束 下一个细胞 设置应用程序=无 应用 .EnableEvents=True .ScreenUpdate=True 以 端接头
您可以从下面的链接了解更多信息Excel nge 变暗rng As范围 应用 .EnableEvents=False .ScreenUpdate=False 以 设置sh=图纸(“图纸1”) Set-OutApp=CreateObject(“Outlook.Application”) 对于sh.Columns(“B”).Cells.SpecialCells(xlCellTypeConstants)中的每个单元格 '在每行的C:Z列中输入路径/文件名 设置rng=sh.Cells(cell.Row,1).范围(“C1:Z1”) 如果单元格值像“*@*。?*”和_ Application.WorksheetFunction.CountA(rng)>0则 Set-OutMail=OutApp.CreateItem(0) 发邮件 .to=单元格.Value .Subject=“Testfile” .Body=“Hi”&单元格偏移量(0,-1).Value 对于rng.SpecialCells中的每个文件单元(xlCellTypeConstants) 如果修剪(文件单元)”,则 如果Dir(FileCell.Value)“,则 .Attachments.Add FileCell.Value 如果结束 如果结束 下一个文件单元 .Send'或use.Display 以 发送邮件=无 如果结束 下一个细胞 设置应用程序=无 应用 .EnableEvents=True .ScreenUpdate=True 以 端接头,excel,vba,email,outlook,Excel,Vba,Email,Outlook,您可以从下面的链接了解更多信息 类似于“是”的东西,它工作得很好!非常感谢您的帮助和建议!我是一个初学者,所以在我真正养成坏习惯之前,这些建议非常有用。谢谢你这么有效率!不确定否决票的目的是什么,因为它似乎已经解决了OP的问题,尽管它没有被接受。 Sub SendEMail() Dim Email As String Dim Subj As String Dim Msg As String Dim URL As String Dim r As Integer Dim x As Double Di
类似于“是”的东西,它工作得很好!非常感谢您的帮助和建议!我是一个初学者,所以在我真正养成坏习惯之前,这些建议非常有用。谢谢你这么有效率!不确定否决票的目的是什么,因为它似乎已经解决了OP的问题,尽管它没有被接受。
Sub SendEMail()
Dim Email As String
Dim Subj As String
Dim Msg As String
Dim URL As String
Dim r As Integer
Dim x As Double
Dim OApp As Object
Dim OMail As Variant
Dim Signature As String
Dim strbody As String
strbody = "<html><body>"
With Sheets("Email").Select
lastrow = Cells(Rows.Count, "B").End(xlUp).Row
End With
For r = 2 To lastrow
Set OApp = CreateObject("Outlook.Application")
Set OMail = OApp.CreateItem(0)
' Get the email address
Sheets("Email").Select
Email = Cells(r, "F")
' Message subject
Sheets("Email").Select
Subj = "Renewal for " & Cells(r, "B").Text & " Contract " & Cells(r, "A").Text & " Effective " & Cells(r, "C").Text
' Message body
Sheets("Email").Select
strbody = strbody & "Dear " & Cells(r, "AR").Text & ", <br><br>" & _
"I will be working with you on " & Cells(r, "B") & ", client number " & Cells(r, "A") & ", which is effective " & Cells(r, "C") & ".<br><br>" & _
"For this year's contract, we are requesting the following information: <br>" & _
"<li>" & Cells(r, "AH") & "</li>" & "<br><br>" & _
"The application form may be downloaded from:<br>" & _
"<li>Option #1</li>: " & "<a href=""" & "Link#1" & """>" & "Link#1" & "</a>" & "<br>" & _
"<li>Option #2</li>: " & "<a href=""" & "link#2" & """>" & "link#2" & "</a>" & "<br><br>" & _
"Once we receive the requested information, you will receive your contract within 5 business days. Should you have any questions, please don't hesitate to contact me at this email address or phone number <br><br>" & _
"As always, we would like to thank you for your business. <br><br>" & _
"Regards, <br>"
On Error Resume Next
Sheets("Email").Select
With OMail
.Display
.To = Email
.Subject = Subj
.HTMLBody = strbody & vbNewLine & .HTMLBody
End With
Next r
On Error GoTo 0
Set OMail = Nothing
Set OApp = Nothing
End Sub
strbody = strbody & "Dear " & Cells(r, "AR").Text & ", <br><br>" & _
"I will be working with you on " & Cells(r, "B") & ", client number " & Cells(r, "A") & ", which is effective " & Cells(r, "C") & ".<br><br>" & _
"For this year's contract, we are requesting the following information: <br>" & _
"<li>" & Cells(r, "AH") & "</li>" & "<br><br>" & _
"The application form may be downloaded from:<br>" & _
"<li>Option #1</li>: " & "<a href=""" & "Link#1" & """>" & "Link#1" & "</a>" & "<br>" & _
"<li>Option #2</li>: " & "<a href=""" & "link#2" & """>" & "link#2" & "</a>" & "<br><br>" & _
"Once we receive the requested information, you will receive your contract within 5 business days. Should you have any questions, please don't hesitate to contact me at this email address or phone number <br><br>" & _
"As always, we would like to thank you for your business. <br><br>" & _
"Regards, <br>"
strbody = "Dear " & Cells(r, "AR").Text & ", <br><br>" & _
"I will be working with you on " & Cells(r, "B") & ", client number " & Cells(r, "A") & ", which is effective " & Cells(r, "C") & ".<br><br>" & _
"For this year's contract, we are requesting the following information: <br>" & _
"<li>" & Cells(r, "AH") & "</li>" & "<br><br>" & _
"The application form may be downloaded from:<br>" & _
"<li>Option #1</li>: " & "<a href=""" & "Link#1" & """>" & "Link#1" & "</a>" & "<br>" & _
"<li>Option #2</li>: " & "<a href=""" & "link#2" & """>" & "link#2" & "</a>" & "<br><br>" & _
"Once we receive the requested information, you will receive your contract within 5 business days. Should you have any questions, please don't hesitate to contact me at this email address or phone number <br><br>" & _
"As always, we would like to thank you for your business. <br><br>" & _
"Regards, <br>"
Sub Send_Files()
'Working in Excel 2000-2016
'For Tips see: http://www.rondebruin.nl/win/winmail/Outlook/tips.htm
Dim OutApp As Object
Dim OutMail As Object
Dim sh As Worksheet
Dim cell As Range
Dim FileCell As Range
Dim rng As Range
With Application
.EnableEvents = False
.ScreenUpdating = False
End With
Set sh = Sheets("Sheet1")
Set OutApp = CreateObject("Outlook.Application")
For Each cell In sh.Columns("B").Cells.SpecialCells(xlCellTypeConstants)
'Enter the path/file names in the C:Z column in each row
Set rng = sh.Cells(cell.Row, 1).Range("C1:Z1")
If cell.Value Like "?*@?*.?*" And _
Application.WorksheetFunction.CountA(rng) > 0 Then
Set OutMail = OutApp.CreateItem(0)
With OutMail
.to = cell.Value
.Subject = "Testfile"
.Body = "Hi " & cell.Offset(0, -1).Value
For Each FileCell In rng.SpecialCells(xlCellTypeConstants)
If Trim(FileCell) <> "" Then
If Dir(FileCell.Value) <> "" Then
.Attachments.Add FileCell.Value
End If
End If
Next FileCell
.Send 'Or use .Display
End With
Set OutMail = Nothing
End If
Next cell
Set OutApp = Nothing
With Application
.EnableEvents = True
.ScreenUpdating = True
End With
End Sub