I'm trying to write a code to create an email for every row of data on my sheet. It seems to be working fine until I added the ".Attachments.Add" line. Am I missing something in my code? Or is there a problem that I am trying identify the file path from a cell?
Sub CreateEmails() Dim objOutlook As Object Set objOutlook = CreateObject("Outlook.Application") Dim objEmail As Object Dim eBody As String Range("A2").Select Do Until IsEmpty(ActiveCell) Set objEmail = objOutlook.CreateItem(olMailItem) eBody = "<p>Hi " & ActiveCell(0, 1).Value & ", </p>" _ & "<p>Message Body</p>" & _ "<p>Thank you!</p><br>" With objEmail .to = ActiveCell(0, 2).Value .Subject = ActiveCell(0, 3).Value .HTMLBody = "<html><head></head><body>" & eBody & "</body></html>" .Attachments.Add ActiveCell(0, 5).Value .Display End With ActiveCell.Offset(1, 0).Select Loop End Sub https://stackoverflow.com/questions/66701528/can-i-add-a-file-path-from-a-cell-in-attachments March 19, 2021 at 09:51AM
没有评论:
发表评论