excel - 如何在 Excel 中使用 VBA 使图片出现在文本框之后
问题描述
我正在尝试向我的合作伙伴发送电子邮件,但我无法弄清楚如何让文本(来自文本框)出现在图片之后。当我更改代码时,文本的格式就会丢失。这是代码
Sub send_mass_email()
Dim i As Integer
Dim name, email, body, subject, copy, place, business As String
Dim OutApp As Object
Dim OutMail As Object
body = ActiveSheet.TextBoxes("TextBox 1").Text
i = 2
Do While Cells(i, 1).Value <> ""
name = Split(Cells(i, 1).Value, " ")(0) 'extract first name
email = Cells(i, 2).Value
subject = Cells(i, 3).Value
copy = Cells(i, 4).Value
business = Cells(i, 5).Value
place = Cells(i, 6).Value
body = Replace(body, "C1", name)
body = Replace(body, "C5", business)
body = Replace(body, "C6", place)
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
With OutMail
.to = email
.cc = copy
.subject = subject
.body = body
.HTMLBody = "<img src='https://i.ibb.co/4gVsz56/fastpass.png'> " & _
.HTMLBody
.display
'.Send
End With
body = ActiveSheet.TextBoxes("TextBox 1").Text
i = i + 1
Loop
Set OutMail = Nothing
Set OutApp = Nothing
End Sub
解决方案
不知道你为什么使用.Body
AND.HTMLBody
因为它们不能一起工作......你想要这样的东西
With OutMail
.to = email
.cc = copy
.subject = subject
.HTMLBody = body & "<img src='https://i.ibb.co/4gVsz56/fastpass.png'>"
' or use this line
'.HTMLBody = body & "<br><img src='https://i.ibb.co/4gVsz56/fastpass.png'>"
.display
'.Send
End With