Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

MS Office Word Ribbon Addin

Posted on 2011-10-04
3
Medium Priority
?
485 Views
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.

btnAcceptErr
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
        Next

        Return Nothing

    End Function

Open in new window

0
Comment
Question by:SMcP
  • 2
3 Comments
 
LVL 36

Assisted Solution

by:Miguel Oz
Miguel Oz earned 248 total points
ID: 36915003
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)
0
 
LVL 36

Expert Comment

by:Miguel Oz
ID: 36915014
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.
0
 
LVL 6

Accepted Solution

by:
xenacode earned 252 total points
ID: 36915283
Also, the ribbon button names will not be directly accessible from within the ThisAddin class - you can access them through Globals like so:

Globals.Ribbons.MyRibbonName.MyButtonName

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

Pete
Xenacode Ltd
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It is often necessary in this forum and others to illustrate Word fields as text with the field delimiters replaced with the curly brackets that the delimiters resemble when field codes are being displayed on the document. This means that the text c…
Using Word 2013, I was experiencing some incredible lag when typing.  Here's what worked for me....
In this video, we show how to convert an image-only PDF file into a PDF Searchable Image file, that is, a file with both the image (typically from scanning) and text, which is created in an automated fashion with Optical Character Recognition (OCR) …
Enter Foreign and Special Characters Enter characters you can't find on a keyboard using its ASCII code ... and learn how to make a handy reference for yourself using Excel ~ Use these codes in any Windows application! ... whether it is a Micr…
Suggested Courses

564 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