how to cancel the vba followhyperlink?

随声附和 提交于 2019-12-10 08:57:34

问题


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.


回答1:


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...



来源:https://stackoverflow.com/questions/6829744/how-to-cancel-the-vba-followhyperlink

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!