Oleg Krupnov

Hi,

I'd like to add hyperlinks (link labels) into my Word customization and handle the event when the user clicks the hyperlink (single click) in the document. I have tried the following methods:

1) Add Windows Forms LinkLabel to the document. The problem is that the control doesn't work when the document is viewed zoomed to anything else than 100% (what a ridiculous and disappointing limitation btw!..) Is there any progress with this issue so far

2) Add a VBA's Label ActiveX control (Microsoft Forms ActiveX). This seems to work but after adding the control and saving the document, next time I open it I see the macro security warning that I'd strongly like to avoid. Is there a way to workaround this

3) MacroButton fields - work fine but require double clicking and do not change mouse cursor shape, i.e. do not really look and feel clickable, in contrast to ordinary hyperlinks in HTML pages.

Any ideas

Thanks.


Re: Visual Studio Tools for Office Advise the best way to create a link label in Word customization?

Ji Zhou ¨C MSFT

Hi,

Your description about the three ways is by-design behavior.

There are some limitations of VSTO Winform controls. One of them is that controls will be disabled when they are scaled. You can find more information about all the limitations in this link:

http://msdn2.microsoft.com/en-us/library/ms178765(VS.80).aspx

As to the second way, when we use Macro Code, and set our security policy to high, there will be a Security Warning to help us prevent from risk. You can close the Security Warning by trust the documentĄ¯s location. You can follow one of means in this KB article to do that:

http://support.microsoft.com/kb/812307

Third, MacroButton field is designed to be double click to perform the corresponding macro. And it looks unlike a hyperlink at all. It is designed to be a middle thing between field and control.

Based on my opinion, I would choose the first way. But if that limitation is unacceptable, IĄ¯d use the second way, and avoid the Security Warning by trust the source.

Thanks

Ji






Re: Visual Studio Tools for Office Advise the best way to create a link label in Word customization?

Oleg Krupnov

Thanks, Ji

I understand that everything works "by design", but I still don't understand how to solve my problem.

1) (WinForms) All users have monitors of different resolution. Do you think I should expect them all work with 100% of zoom with the Word document all the time What if they use 75% or 150% even set BY DEFAULT No, I don't think this limitation is acceptable. I don't understand why you choose this way. What is your reasoning

2) (Macro Button Fields) Ok, macro buttons are macro buttons. I've recently stumbled upon Word FormField objects. Unlike ActiveX, these are "native" to Word, but unfortunately in order to make them clickable I need to "protect the form" first, which makes the entire document not editable. Is there a way to activate each form field one by one, without protecting the entire document

3) (ActiveX) I am confused because I only use the standard MS Forms controls (found on the "Control Toolbox" toolbar) installed will EVERY Word copy. I used to think that these controls are granted full trust BY DEFAULT. I do not attach any VBA code to the controls and I do not use custom ActiveX control, so in my opinion, the Word's security warning is completely unsubstantiated. Am I wrong

I can't grant the full trust by location, as you suggest, because the users will create new documents based on my customization template and save them anywhere they like, or even give away to other users who don't have the customization. And I don't want them to see even two warnings: one for the missing customization and the other for potentially harmful macros in the document. You know, I don't think anyone will dare open such documents at all!

Hoping for your help. Thanks




Re: Visual Studio Tools for Office Advise the best way to create a link label in Word customization?

Daniel Molina - MSFT

Hi Oleg,

Control scaling is something we have worked on before but the issue is that WinForms provides a form of pseudo-scaling that would not yield expected results in all cases, so for now we opted for disabling scaled controls.(http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=998503&SiteID=1).

As I imagine you would like an example, the one that comes to my mind is the DatePicker. When you zoom in a document that contains a DatePicker control (therefore making the control larger screenarea-wise) what actually happens is that you will see more months in your control instead of getting a scaled view.






Re: Visual Studio Tools for Office Advise the best way to create a link label in Word customization?

Oleg Krupnov

Thanks Daniel,

After fiddling with ActiveX controls and VBA security, I am arriving at the conclusion that fusing these two heterogenous technologies - VBA and VSTO is perhaps a bad idea and a big pain in the ***. I am now more inclined to completely switch to using only WinForm controls in my customization and let go of the fear that my users may suffer of this limitation.

I have asked one user and he told me he never alters his Word's zoom because his monitor is wide enough to show the entire page at 100%. This is only a single opinion though, and I wonder if Microsoft has made a more representatvie survey regarding this issue. MS team has done a great and laborious job of implementing WinForm controls in documents in VSTO and I believe there should be a strong reasoning for this kind of implementation, even though the control scaling limitation. Can you tell me your reasons, just to set me at rest


Oleg.




Re: Visual Studio Tools for Office Advise the best way to create a link label in Word customization?

Cindy Meister

Oleg, I think your third suggested approach will be your best bet.

You can change the number of required clicks to activate a MacroButton field from two to one using

WordApplication.Options.ButtonFieldClicks = 1

Please note that this applies to the entire application environment. That's usually not an issue, but you need to be aware of the fact. If it would for some reason be an issue (some solution relies on its being a double-click) you'd need to trap some events in order to change back-and-forth when the user moves out of your document.






Re: Visual Studio Tools for Office Advise the best way to create a link label in Word customization?

Oleg Krupnov

Wow, Cindy you are helpful as always. Thanks! You brought me to the idea how I can imitate link labels in Word. It is the following: Create a MACROBUTTON field with a dummy macro name and the link text, and then handle the Document.SelectionChange event to check whether the field's Range has been selected. With a little trickery, I got it to look and work as a single-click link label (and it doesn't depend on the zoom btw). I didn't even need the ButtonFieldClicks option. The only thing is that the cursor doesn't change to "hand" as it should on a hyperlink, but I think it's ok for the user because Word document is not really a read-only browser page, it's an editable document.

To mention my experience with Windows Forms controls inserted to the document has not been satisfactory. Even having reconciled myself with the fact that my links will not work for zoom factors other than 100%, I found that the controls cause a significant slowdown of the document scrolling and repaint, the more so the more controls I insert, unfortunately. I wonder if anyone has obtained good results with those controls at all...