MS Office Word Ribbon Addin

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

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Miguel OzSoftware EngineerCommented:
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)
Miguel OzSoftware EngineerCommented:
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.
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Word

From novice to tech pro — start learning today.