سؤال

I have an excel worksheet with some hyperlinks. Some of them are email addresses.
When a user clicks a hyperlink, I determine whether or not it is an email, using Worksheet_FollowHyperlink(ByVal Target As Hyperlink) and Target.Address like "mailto:*"

What I want now is to cancel the default hyperlink behavior and open the email client myself, programmatically. That way, I can provide a default message and add attachments.

I tried using Cancel = True but it doesn't work. I prefer not to mess with custom hyperlinks because excel generates links to email automatically.

Is it even possible?
Opening the hyperlink seems to happen on another thread.

هل كانت مفيدة؟

المحلول

You cannot prevent a click from following the hyperlink. You can test by yourself by setting a breakpoint in the Worksheet_FollowHyperlink sub. Excel follow the link before executing the code.

I can't see any event procedure that would help interfere and prevent the behavior.

Another tip i could give is to prevent Excel from creating hyperlinks or to do it by vba with a Worksheet_Change event.
Next, you could intercept a peuso-click with a Worksheet_SelectionChange and check if the cell contains a mail address.

Last but not least, if you do know that the e-mail client is Outlook, you can probably get the newly created mail to add attachments, recipients, message...

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top