【发布时间】:2018-03-21 23:41:48
【问题描述】:
我正在使用 excel 来收集、格式化和通过电子邮件将信息发送给其他用户。我想用不同的颜色格式化此代码生成的信息,以使其脱颖而出。我知道“.Font.colorindex = ??”,但对变量类型的内部结构不够熟悉,无法获得我想要实现的功能......
例子:
Private Sub CommandButton1_Click()
Dim outlookApp As Outlook.Application
Dim outlookMail As Outlook.MailItem
Dim ExtractedText As String
Set outlookApp = New Outlook.Application
Set outlookMail = outlookApp.CreateItem(olMailItem)
With outlookMail
.To = "person@company.com"
.CC = ""
.BCC = ""
.Subject = "This is a test email automated by excel"
.BodyFormat = olFormatHTML
.HTMLBody = "This is an automated message generated from an Excel macro.<p>Info 1 " & Sheet1.Cells(2, 1) & " Info 2: " & Sheet1.Cells(2, 2) & " Info 3 " & Sheet1.Cells(2, 3) & ". Please see attached."
.Attachments.Add "C:\Users\xyz\Desktop\Test Attachment.xlsx"
.Importance = olImportanceHigh
.Send
End With
Set outlookMail = Nothing
Set outlookApp = Nothing
End Sub
我想将“ExtractedText”定义为 Cell(2, 1),为其设置颜色并将其插入到电子邮件正文中,以代替上面使用的“Sheet1.Cells(2, 1)”。我花了几个小时搜索和尝试不同的方法来展示它。在等待我订购的 VBA 编码书籍到货时,我想我应该问问社区。p>
提前致谢!
【问题讨论】:
-
所以,如果您知道应该使用
.font.colorindex = ##,那么只需查找调色板(例如:msdn.microsoft.com/en-us/vba/excel-vba/articles/…)。另外,您是否尝试在将单元格中的值放入电子邮件之前或之后为它们着色?
标签: excel string vba variables colors