none
Handle Hyperlink click event on Outlook 2007 MailItem RRS feed

  • Question

  • Hello experts, I am working with an Outlook 2007 VSTO add-in in VS 2008 (C#).

    I am wondering if it is possible to handle/trap the click event of hyperlinks in the body of a MailItem object. I need to do a custom operation (need to execute a code snippet) in the event of the click operation.

    Thanks in advance...

    -Jahedur Rahman


    Wednesday, July 6, 2011 9:43 AM

Answers

  • Hi Jahedur,

    Sorry for delay response.

    I will show the snippet that you can use in the mail’s HTMLBody it will open Access and show the form.

    <script language="Javascript">
    function Click(){
    	alert("Hello World");
    	var cmd = new ActiveXObject('WScript.Shell');
    	cmd.Run('msaccess.exe C:\\Users\\v-yangxu\\Desktop\\Database21.accdb /x Form1');
    }
    </script>
    <a onClick="javascript:Click();">Click</a>

    Before you use it you need create a Macro in Access file which named “Macro1” to open the form.

    I you omit “/x Marco1” you will open Access only but it seems more safe.

    If I have misunderstood anything, please feel free to let me know.

    Have a good day,

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.


    Friday, July 15, 2011 5:51 AM
    Moderator

All replies

  • Hi Jahedur,

    Thanks for posting in the MSDN Forum.

    Would you please clarify what’s action you will do when you click the hyperlink in your mail item body?

    Do you what to handle some Outlook issues via PIA when click the hyperlink? If it is, I think your goal is hard to approach. You are able to use javascript in you mail’s HTML body to handle click event to handle your issue. If you want to handle Outlook issues such as Create a new mail item, move the mail item to a specific folder etc. via click that hyperlink you need invoke Outlook’s COM Interface in your javascript scenario. However I would not recommend you do that for security issues.

    I hope what I said can help you.

    Have a good day,

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Friday, July 8, 2011 3:06 AM
    Moderator
  • Thanks Tom_Xu for your response.

    Actually the recipients of this kind of emails will be using Outlook 2007 and will be having a desktop application (MS Access) at a specific location (e.g.: %programfiles%\MyApp\abc.mdb). The hyperlink should contain a link to a specific form in the Access application and should open the form when the link is clicked.

    I was trying to set the hyperlink address to somewhat like <%programfiles%\MyApp\abc.mdb#Form1>, but it did not work. So, now I am looking for a way to handle the click event to execute a code snippet within the add-in that will open the targeted form in MS Access.

    Please let me know if you need further clarification.

    -Jahedur Rahman

    Friday, July 8, 2011 4:15 AM
  • Hi Jahedur,

    Sorry for delay response.

    I will show the snippet that you can use in the mail’s HTMLBody it will open Access and show the form.

    <script language="Javascript">
    function Click(){
    	alert("Hello World");
    	var cmd = new ActiveXObject('WScript.Shell');
    	cmd.Run('msaccess.exe C:\\Users\\v-yangxu\\Desktop\\Database21.accdb /x Form1');
    }
    </script>
    <a onClick="javascript:Click();">Click</a>

    Before you use it you need create a Macro in Access file which named “Macro1” to open the form.

    I you omit “/x Marco1” you will open Access only but it seems more safe.

    If I have misunderstood anything, please feel free to let me know.

    Have a good day,

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.


    Friday, July 15, 2011 5:51 AM
    Moderator
  • Thanks a lot Tom_Xu... This is what I was looking for...!

    I will try this and will let you know the status.

    -Jahedur Rahman

    Friday, July 15, 2011 8:00 AM
  • Tom_Xu, Yes...it works!

    But it works only with macro not with form.

    Thanks a lot for your help. But I need a bit more help, that is, it opens a new instance of the Access Application each time I click on the link. Is it possible to change the code so that it would open the form only if the app is already open/running, or open the app if not running?

    I also need to send a parameter to the macro as well, can you please let me know if this is possible?

    Thanks once again...

    -Jahedur Rahman

    Friday, July 15, 2011 10:32 AM
  • Hi Jahedur,

     

    I tried a great deal of ways to recover your issue. But I wasn’t able to find any solution about it. Some of the parameter of the command line seems not work at all. And I won’t recommend you use the code which I mentioned in the past reply due to security reason.

     

    If you only want to access Access from the native computer I would recommend you handle this via windows form application or WPF application. If you want to handle it via Outlook I would recommend you create a ribbon button or Custom Task Pane to handle it.

     

    If you need to handle Access issue on the computer which on network or a location net I would recommend you develop a Outlook add-in to add a Ribbon button or context menu item to Outlook to handle it.

     

    Have a good day,

     

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, July 20, 2011 3:01 AM
    Moderator
  • Thanks a lot Tom_Xu for the clarification.

    I think I was trying to do something not usual with Access and Outlook. But I will try some other options with my Add-In that is already in place to do this.

    Thanks again for your effort!

    -Jahedur Rahman


    Wednesday, July 20, 2011 5:04 AM