Ribbon adding control

I

Igor

Hello,

I have a ribbon and I want to add a button to it that will add a new text
content control to the document with the name myText. Any ideas on how to
code the event handler for this?

Igor
 
D

Doug Robbins - Word MVP

Assuming that you know how to modify the Ribbon,

Dim cc As ContentControl
With ActiveDocument
Set cc = .ContentControls.Add(wdContentControlText, Selection.Range)
cc.Title = "myText"
End With

If not, see the following page of fellow MVP Greg Maxey's website:

http://gregmaxey.mvps.org/Customize_Ribbon.htm

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
 
I

Igor

Doug,

This doesn't seem to work. I am trying to code the click event handler:
private void btnTestButton_Click(object sender, RibbonControlEventArgs e)
{

myClass.ThisDocument thisDoc = new ThisDocument();
Word.Selection selection =
myClass.ThisApplication.ActiveDocument.Application.Selection;

object Range = selection.Range;

thisDoc.ThisApplication.ActiveDocument.ContentControls.Add(Word.WdContentType.wdContentControlText, ref Range);
}
 
I

Igor

I addded the below code to the click event handler and removed the rest. It
works but I still need to change some properties of the contentcontrol before
adding it.

object Range = Type.Missing;

Globals.ThisDocument.ContentControls.Add(Microsoft.Office.Interop.Word.WdContentControlType.wdContentControlText, ref Range);
 
C

Cindy M.

Hi Igor,
Globals.ThisDocument.ContentControls.Add(Microsoft.Office.Interop.Word.WdContentControlType.wdContentControlText, ref Range);

This looks like VSTO? I recommend you post VSTO-related questions to the dedicated forum. This newsgroup targets VBA
developers. While it's always a great place to get information about Word and its object model, when you get into VSTO objects
there really isn't any support.

http://social.msdn.microsoft.com/Forums/en-US/vsto/threads?lc=1033&prof=required&page=1

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or reply in the newsgroup and not by e-mail :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top