Sorry, but I can't see any description on how to use functions in the ribbon code from Word templates.
I would love to see more specific examples.
(I do know how to Google)
Main Topics
Browse All TopicsHi,
I have a VSTO Ribbon written in Visual Studio 2008. This ribbon will be installed on all computers on our network. As part of the ribbon I have some functions.
Is it possible to call these functions from Word macro enabled templates without adding the templates the Ribbon project?
If yes - how do I do it?
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Yes it is possible
Let button1 be a button on the ribbon
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As Microsoft.Office.Tools.Rib
' Myshow is the macro name written in the word template
Globals.ThisDocument.Appli
End Sub
You can do this providing your VSTO add-in exposes its functionality correctly.
Within your VBA you can access the COMAddIns property of the Application object. This is a collection of objects representing the loaded add-ins. Each of these objects has a property called Object of type Object which you can access from within your VSTO solution.
Inside your VSTO ThisAddIn class, override the RequestComAddInAutomationS
Protected Overrides Function RequestComAddInAutomationS
Dim myAddIn = MyClassThatDoesStuff
Return myAddIn
End Function
Create a public class (in the above code, it's MyClassThatDoesStuff) in your VSTO solution that exposes the public methods that you want to be able to call from your VBA.
So now, in your VBA code you can find the Addin like this:
For Each addIn As COMAddIn In Application.COMAddIns
If addIn.ProgId = "MyVSTOAddin.Whatever" AndAlso addIn.Object IsNot Nothing Then
'call some methods
addIn.Object.MyMethod
End If
Next
(where "MyVSTOAddin.Whatever" is your VSTO AddIn name.)
I hope that makes sense. If not, let me know.
Pete
Xenacode Ltd
You will need to keep a reference to the Testing object that you create within ThisAddIn or it will be Null/Nothing when the VBA tries to call the ThorTest method. My sample didn't show that so sorry for not being specific. Also try moving the Testing class outside of class ThisAddIn like so:
Public Class ThisAddIn
Private myTesting as Testing
Protected Overrides Function RequestComAddInAutomationS
myTesting = New Testing()
Return myTesting
End Function
End Class
Public Class Testing
Sub ThorTest()
MsgBox("It works!!")
End Sub
End Class
I think that should do it.
Pete
Can you check if the addin is actually loaded? Perhaps you could add a line into the VBA like this to check if the add-in has been found in the COMAddIns collection:
Sub Testing()
Dim AddIn As COMAddIn
For Each AddIn In Application.COMAddIns
MsgBox AddIn.ProgID
If AddIn.ProgID = "CPHRibbon" And Not IsNull(AddIn.Object) Then
MsgBox ("Found the addin")
AddIn.Object.ThorTest
End If
Next
End Sub
and perhaps another in the addin startup to confirm your VSTO code is running:
Private Sub ThisAddIn_Startup(ByVal sender As Object, ByVal e As System.EventArgs) _
Handles Me.Startup
MsgBox ("Addin starting")
End Sub
Pete
Business Accounts
Answer for Membership
by: suvmitraPosted on 2009-10-26 at 07:57:15ID: 25662861
These threads could be helpful for you:
http://social.msdn.mic rosoft.com /Forums/en -US/vsto/t hread/f283 e426-a2bd- 4b18-a44e- 88f316f96e b4
http://m sdn.micros oft.com/en -us/magazi ne/cc50764 3.aspx