views:

18

answers:

1

I want to add in a C# application a bookmark to a particular range to my Word document at runtime . I have found one solution Microsoft.Office.Tools.Word.Bookmark bookmark1; bookmark1 = this.Controls.AddBookmark(this.Paragraphs[1].Range, "bookmark1");

But an error shows that the Windows form has no definition for AddBookmark. Please help.

A: 

You are using a WinForms application, therefore by using the keyword this it will refer to the form class you are using which does not have a definition for Controls.AddBookmark.

I suggest you take a look here: http://msdn.microsoft.com/en-us/library/cc442946.aspx

This will show you how to create a word addin from which you can then use this code to add a bookmark.

Microsoft.Office.Tools.Word.Bookmark bookmark1; bookmark1 = this.Controls.AddBookmark(this.Paragraphs[1].Range, "bookmark1");
kyndigs
can't we replace "this" with the variable of type supporting Addbookmark? I want to add this code to my managedMFC application
sshah
Yes it is possible using System.InteropServices, take a look here: http://msdn.microsoft.com/en-us/library/system.runtime.interopservices.marshal.getactiveobject.aspx
kyndigs
Also take a look here this may help: http://support.microsoft.com/default.aspx?scid=kb;en-us;316126
kyndigs