在Outlook中使用VBA与Emojis发送文本

我有一些VBA代码,用于将Outlook中的文本发送给我的项目团队成员。 对于一些背景:对于非AT&T用户,我们没有任何问题通过将人员号码全部插入到Outlook电子邮件的收件人字段中来从Outlook发送文本消息。 但是,所有AT&T用户都将收到文本作为群组消息,这是我们想要避免的。 非AT&T用户在我们发送群组时正确接收个别文本。

我们编写了一些VBA代码来循环使用AT&T号码的电子表格,以便Outlook根据AT&T号码发送一封电子邮件。 这对我们来说工作得很好,但是,我们希望在我们发送的文本中添加一些表情符号。 我做了很多谷歌search和searchstackoverflows的问题,我似乎无法find任何代码为此目的而build。 当谈到VBA时,我也是一个完整的noob,而且我把这个解决scheme拼凑在一起,远没有从同事的帮助和通过互联网上的线程阅读。 这个关于emojis的东西给了我足够的麻烦,我想我会分解并提交这个post。

作为参考,这里是我的代码:

Sub EmojiTest() Dim objOutlook As Outlook.Application Dim objOutlookMsg As Outlook.MailItem Dim objOutlookRecip As Outlook.Recipient Dim MobileNumber As String ' Create the Outlook session. Set objOutlook = CreateObject("Outlook.Application") Set xlApp = CreateObject("Excel.Application") 'Grab list from Excel Set xlAtt = xlApp.Workbooks.Open("C:\Users\Username\Desktop\Spreadsheet with AT&T numbers.xlsx") xlAtt.Activate LastRow = xlAtt.ActiveSheet.Range("B" & xlAtt.ActiveSheet.Rows.Count).End(-4162).Row For i = 1 To LastRow xlAtt.Activate MobileNumber = xlAtt.ActiveSheet.Range("B" & i).Value ' Create the message. Set objOutlookMsg = objOutlook.CreateItem(olMailItem) objOutlookMsg.SentOnBehalfOfName = "TeamAccount@work.com" With objOutlookMsg ' Add the To recipient(s) to the message. Set objOutlookRecip = .Recipients.Add(MobileNumber) objOutlookRecip.Type = olTo ' Set the Subject, Body, and Importance of the message. .Subject = "Emoji Test" .Body = "Text with emojis" .Save .Send End With Next i Set objOutlook = Nothing xlApp.Workbooks.Close Set xlApp = Nothing End Sub 

由于我完全没有使用VBA的经验,而且一般的编程经验有限,所以这是我从来没有想过的代码。 任何帮助深表感谢。

更改:

.Body = "Text with emojis"

至:

.Body = "\ud83d\ude03"

完整列表可在这里 。 复制名为Java转义string的框。

\ u转义unicode序列,因此input“\ u”和UTF-16序列应该允许您插入任何表情符号。

一些Emojis实际上是2个独立的字符序列,所以你必须链接在一起。

我知道了!

 Sub EmojiTest() Dim objOutlook As Outlook.Application Dim objOutlookMsg As Outlook.MailItem Dim objOutlookRecip As Outlook.Recipient Dim MobileNumber As String Dim strbody As String ' Create the Outlook session. Set objOutlook = CreateObject("Outlook.Application") Set xlApp = CreateObject("Excel.Application") 'Grab list from Excel Set xlAtt = xlApp.Workbooks.Open("C:\Users\user\Desktop\Spreadsheet.xlsx") xlAtt.Activate LastRow = xlAtt.ActiveSheet.Range("B" & xlAtt.ActiveSheet.Rows.Count).End(-4162).Row For i = 1 To LastRow xlAtt.Activate MobileNumber = xlAtt.ActiveSheet.Range("B" & i).Value ' Create the message. Set objOutlookMsg = objOutlook.CreateItem(olMailItem) objOutlookMsg.SentOnBehalfOfName = "Team@work.com" strbody = "<BODY style=font-size:11pt;font-family:Segoe UI Symbol>&#127881;Congrats!<p>Paragraph 2.<p>Paragraph 3.</BODY>" With objOutlookMsg ' Add the To recipient(s) to the message. Set objOutlookRecip = .Recipients.Add(MobileNumber) objOutlookRecip.Type = olTo ' Set the Subject, Body, and Importance of the message. .Subject = "Emoji Test" .HTMLBody = strbody .Save .Send End With Next i Set objOutlook = Nothing xlApp.Workbooks.Close Set xlApp = Nothing End Sub 

基本上,我不得不把我的消息转换成HTML。 我在顶部使用“Dim strbody As String”,然后在With语句中使用“.HTMLBody = strbody”。 一旦我这样做,使用HTMLhex代码input我的表情符号是微不足道的。 这里是我使用HTMLhex代码的页面(&#127881): http : //www.fileformat.info/info/unicode/char/1f389/index.htm 。

了解了很多关于使用VBA这样做,所以很有趣。

感谢您的帮助山姆。

Interesting Posts