VBA Hyperlink (1 Viewer)

jacko6

Member
Local time
Today, 15:03
Joined
Jul 17, 2023
Messages
36
I'm trying to format a hyperlink string in vba and then use the hyperlink in the body of the email msg I am creating using the CDO library.

However the hyperlink displays as is, rather than just the text.

The easiest way to test what I mean is to create a string in VBA that contains the url and the text to display, then paste it into a mail client to see if it works. I can't get it to work.

Note: I would paste the vba string example into this post but it keeps getting flagged as spam and won't let me!
 
Last edited:
Hi. A hyperlink is an HTML tag, which is just a text. To properly display it, the email client has to be in Rich Text or HTML mode. Have you tried that?
 
Yes I have tried that. Try pasting the text in the attached image into a mail client to see what I mean.

(I had to use an image as pasting the link into this post results in it getting blocked as spam)

hlinkissue.png
 
OK, it doesn't copy all of the text in the image for me. I get the following:
Code:
<a href=https://www.w3sch001s . com/>Visit

Code:
<a href=https://www.w3schools.com/>Visit W3Schools.com!</a>
If I copy and paste this text into an email client, it just pastes the html tag verbatim, it does not create a link. Usually there is an insert hyperlink function in an email client to handle that. This is exactly how you enter hyperlinks in an access hyperlink field. So I'm not sure what you are trying to do here.
 
Last edited:
Yes it pastes verbatim which illustrates the issue.

So referring to my original post, I am creating the hyperlink string in vba, then using it in the body of an email which I create via vba using the CDO library, and I get the same result as I do when pasting into a mail msg.

Is there a way of formatting the hyperlink string in vba so the email msg displays the "text to display" part only?
 
If we are talking about an access hyperlink field, then just pressing F2 on the field will convert the displayed text into the hashtag separated version. then copying that first part of the text string will get you exactly what you want. The code could split on the # symbol and you can easily get the display text only.

Code:
AWF Thread Text#https://www.access-programmers.co.uk/forums/threads/vba-hyperlink.331479/#
 
Thanks, but what I am talking about is creating an email msg in VBA that contains a hyperlink in the body of the email.

As an eg, in the email the hyperlink should look like this Visit W3Schools.com!

And when you click the hyperlink you would be taken to the url.
 
I solved it.

In the CDO library I was using the .TextBody parameter. I changed this to .htmlBody and the link now formats correctly. Of course this means you need to format the entire body as html, not just the link.

I would post the code but no matter how I try, I get a popup saying the post contains spam.
 
I solved it.

In the CDO library I was using the .TextBody parameter. I changed this to .htmlBody and the link now formats correctly. Of course this means you need to format the entire body as html, not just the link.

I would post the code but no matter how I try, I get a popup saying the post contains spam.
Congratulations. Glad to hear you got it sorted out. Good luck with your project.
 

Users who are viewing this thread

Back
Top Bottom