MS Office Word Ribbon Addin

Posted on 2011-10-04
Last Modified: 2012-06-27
Hi guys.

I've been programming for a while but am new to programming Office Applications and AddIns in VS2010 so I hope you will bear with me.

I've created a new project WordAddIn1
and added a Ribbon and configured it with buttons

In my ThisAddIn_Startup code I want to interogate the current document and based on whether a customproperty exists or not, I want to disable the buttons.

but when I do the btn1.enable = false I get a error... as per the image.

I'm sure this is a basic error on my part so many thanks for the help in moving forward.

Private Sub ThisAddIn_Startup() Handles Me.Startup

        wrdDoc = Me.Application.ActiveDocument

        Dim properties As Microsoft.Office.Core.DocumentProperties
        properties = CType(wrdDoc.CustomDocumentProperties, Office.DocumentProperties)

        If ReadDocumentProperty("docProperty") = Nothing Then
            btn1.enable = false
        End If

    End Sub

Private Function ReadDocumentProperty(ByVal propertyName As String) As String
        Dim properties As Office.DocumentProperties
        properties = CType(wrdDoc.CustomDocumentProperties, Office.DocumentProperties)

        Dim prop As Office.DocumentProperty

        For Each prop In properties
            If prop.Name = propertyName Then
                Return prop.Value.ToString()
            End If

        Return Nothing

    End Function

Open in new window

Question by:SMcP
    LVL 35

    Assisted Solution

    by:Miguel Oz
    At your Ribbon1.Designer.cs, check that: (I assume your ribbon is called Ribbon1)
    private Microsoft.Office.Tools.Ribbon.RibbonButton btnAccept

    is internal or public. (You can do this using the property window as well)
    LVL 35

    Expert Comment

    by:Miguel Oz
    Apologies in VB will be : shared or public
    Private Dim btnAccept As Microsoft.Office.Tools.Ribbon.RibbonButton
    Next time include the question in the VSTO zone.
    LVL 6

    Accepted Solution

    Also, the ribbon button names will not be directly accessible from within the ThisAddin class - you can access them through Globals like so:


    Where MyRibbonName is the name of the ribbon and MyButtonName is the najme of the button e.g. btnAccept.

    Xenacode Ltd

    Featured Post

    Gigs: Get Your Project Delivered by an Expert

    Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

    Join & Write a Comment

    Introduction Authors who set out to write any sort of lengthy piece for online submission—be it a long question or comment on a technical form, an article, or a substantial blog entry—often find it useful to work up a draft in an editor other t…
    Shortcuts in Word Just the other day I had a training for Microsoft and they wanted me to show how well the new Windows and Office behaved on a touch device, which by the way is great, but it was only then that I realized that using keyboard shortc…
    This video teaches the viewer how to align pictures around text while keeping the text properly aligned in the document.
    Learn how to make your own table of contents in Microsoft Word using paragraph styles and the automatic table of contents tool. We'll be using the paragraph styles in Word’s Home toolbar to help you create a table of contents. Type out your initial …

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now