none
Show/Hide Ribbon depending on where the document is being opened from... RRS feed

  • Question

  • Good afternoon

    I have created a tab/ribbon (Add-ins) for Word, xml looking as below:

    <?xml version="1.0" encoding="UTF-8"?> <customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" onLoad="Ribbon_Load"> <ribbon> <tabs> <tab idMso="TabAddIns" getVisible="GetVisible"> <group id="ContentGroup" label="Custom"> <button id="sendToGPButton" label="Send To GP" screentip="Send to GP" onAction="OnSendToGPButton" supertip="Click here to Send this letter to GP"/> </group> </tab> </tabs> </ribbon> </customUI>

    I want to show the tab/ribbon only if Word is opened from 2 specific web applications, so I implemented the GetVisible in myRibbon.vb:

    Public Function GetVisible(ByVal control As Office.IRibbonControl) As Boolean Try Dim currentRange As Word.Range = Globals.ThisAddIn.Application.Selection.Range Dim filePath As String = currentRange.Application.ActiveDocument.FullName Dim allowedURLS As String() = System.Configuration.ConfigurationSettings.AppSettings.Get("allowedURLs").ToString().Split(";") Return True Catch ex As Exception MsgBox("exception: " & ex.Message) Return True End Try End Function

     

    I know this function is not finished, I just wanted to make sure the ribbon would appear/disappear when word is called from the Web Application. If I run the ribbon from VS2010 (pressing F5), the ribbon is displayed, no problem. However, if I go to the web application and invoke the word document from there, I get an exception (Object instance not set to reference) and the ribbon is not displayed - .Application.ActiveDocument.fullname is breaking it.

    what I want to do is to get the path of the document and if it comes from certain URLs, display the ribbon, and hide it otherwise.

    any ideas on how to get this?

    Kind regards

    Carlos

    Wednesday, May 16, 2012 2:45 PM

Answers

  • Hi T.X.

    all sorted, thanks. My colleague took a different approach (hide ribbon from the addin file instead of the ribbon file) and it's fine now.

    Cheers

    C

    Thursday, May 17, 2012 1:24 PM

All replies

  • Hi Carios,

    First, where is the configuration file exists? It's based on my experience that you will get configuration file in Debug folder on your develop machine, however you won't get it on the install folder of your add-in.

    Second, "only if Word is opened from 2 specific web applications", Please confirm the web appliction will inovke MSWord on your client machine. It usual use other technic to express the similar UI which like Office Suite do.

    Best Regards,

    T.X.

    Thursday, May 17, 2012 6:04 AM
  • Hi T.X.

    thanks for your reply. The configuration file is not the problem, it's reading it properly (tested).

    I can confirm that the web application will invoke word on the client machine and once it's opened, download the html text that will be displayed.  

    Thanks

    Thursday, May 17, 2012 8:45 AM
  • Hi T.X.

    all sorted, thanks. My colleague took a different approach (hide ribbon from the addin file instead of the ribbon file) and it's fine now.

    Cheers

    C

    Thursday, May 17, 2012 1:24 PM