I'm generating an Outlook email, which has an HTML body, via Excel VBA.
I would like to @ a contact in my organisation in the body. e.g. @Bloggs, Joe
Mention
is a functionality added to Outlook in the last few years and it seems it's an HTML link. How do I ensure Outlook formats this mention
correctly?
Would the below suffice for Outlook to recognise this as a mention?
<a href="mailto:[email protected]">
<span style='font-family:"Arial",sans-serif;mso-no-proof:yes;text-decoration:none; text-underline:none'>@Bloggs, Joe</span>
The trick seems to be in the id
of the anchor tag:
OWAAM
(I suspect it stands for "Outlook Web Access At Mention", as that's where the feature originated), followed by a 32 character hex value, followed by Z
.For instance:
<a id="OWAAM954ABFF4E42A42989C2192D3F93BB32DZ"
href="mailto:[email protected]">Immo Landwerth</a>
This code works for me (C#):
static string GetMentionHtml(string email, string name)
{
var guid = Guid.NewGuid().ToString("N").ToUpper();
var id = $"OWAAM{guid}Z";
return = $"<a id=\"{id}\" href=\"mailto:{email}\">@{name}</a>";
}
And in case you need it in VBA:
Function GetMentionHtml(email As String, name As String) As String
Dim id As String
Dim html As String
id = "OWAAM" & NewGuid() & "Z"
html = "<a id=""" & id & """ href=""mailto:" & email & """>@" & name & "</a>"
GetMentionHtml = html
End Function
' Sadly there is no "get me a GUID" in VBA, but this is good enough.
' Source: https://www.codegrepper.com/code-examples/vb/excel+vba+generate+guid+uuid
Function NewGuid() As String
Dim k&, h$
NewGuid = Space(36)
For k = 1 To Len(NewGuid)
Randomize
Select Case k
Case 9, 14, 19, 24: h = "-"
Case 15: h = "4"
Case 20: h = Hex(Rnd * 3 + 8)
Case Else: h = Hex(Rnd * 15)
End Select
Mid$(NewGuid, k, 1) = h
Next
NewGuid = Replace(NewGuid, "-", vbNullString, Compare:=vbTextCompare)
End Function
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With