0

I am using VBA to loop through a range, populate a email body & dynamic link, then send to the rows email.

Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
    With OutMail
        .SentOnBehalfOfName = "fake_email@fake.com"
        .to = Target
        .Subject = "HALP ME PLZ :)"
        .HTMLBody = "<font size=3>" _
                    & "Hello " & Application.WorksheetFunction.Proper(Split(Target.Offset(, 3), " ")(0)) & ", " _
                    & "<br><br>" _
                    & "<A href= google.com/" & Target.Offset(, 6) & "> CLICK HERE</A>"   '<--- PROBLEM LINE

        .Send
        Target.Offset(, -1) = "Sent"

    End With

The link in the email works fine on Windows & Mac when using Outlook (web or desktop). I am using the a href tag to create the link. However, when the end users are using the Apple Native Email application, the links are broken. What ends up happening is the links are prefixed with text that appear to be in the format x-webdoc://[Random Key][desired link per macro]

x-webdoc://EADECCCC-5736-4513-B65E-B560FCBC32D8www.google.com/test_input

The user is not able to clink the link right from email to complete the workflow so I am wondering:

Is there anyway to modify the code to ensure the link is rendered properly on Outlook and Apple Mail?

urdearboy
  • 14,439
  • 5
  • 28
  • 58
  • From what I can tell, this is a known bug on the Apple Mail app but hoping there is a work-around. Plz let me know if anyone needs any more [info from me](https://www.youtube.com/watch?v=5cc_h5Ghuj4) – urdearboy Aug 01 '22 at 17:54
  • 1
    You can try to use the complete url (including _https://_ or _http://_). – Shrotter Aug 01 '22 at 18:10
  • Also good practice to *quote* the href attribute value. – Tim Williams Aug 01 '22 at 18:27
  • 1
  • @TimWilliams mine is quoted - not sure I follow – urdearboy Aug 01 '22 at 18:33
  • @Shrotter - post that as a solution. It looks like that is doing the trick – urdearboy Aug 01 '22 at 18:37
  • Your href attribute value is *not* quoted in the code you posted. https://mathiasbynens.be/notes/unquoted-attribute-values#:~:text=The%20HTML%20specification%20says%3A,either%20single%20or%20double%20quotes. – Tim Williams Aug 01 '22 at 18:42
  • Now I see - thanks @TimWilliams - combining what you said with Shrotter seems do be doing the trick. IDK how I missed the link being incomplete. The link working on windows made me skip right past issues in my code and I found many people pointing the finger to Apple Mail as the culprit and ran with that – urdearboy Aug 01 '22 at 18:47

1 Answers1

1

Include scheme/protocol in the link, and as TimWilliams pointed out quote the href attribute valve:

.HTMLBody = "<font size=3>" & "Hello " & Application.WorksheetFunction.Proper(Split(Target.Offset(, 3), " ")(0)) & ", " _
                    & "<br><br>" _
                    & "<a href='https://www.google.com/" & Target.Offset(, 6) & "'> CLICK HERE</a>"
Shrotter
  • 350
  • 3
  • 9