'Word.Bookmarks' does not contain a definition for 'Item'

D

doru.bargaoanu

Hi,

I have this configuration :WindowsXP SP2, Microsoft .NET Framework
1.1,VS.Net, MS Office Word 2003,Office 2003 Primary Interop Assemblies
(O2003PIA) and I get this error when I try to insert a text on a
bookmark.

'Microsoft.Office.Interop.Word.Bookmarks' does not contain a definition
for 'Item'

Here is the function I'm using :

private void BookMarkReplaceRange(ref Word.Document ThisDocument,
string
bookmarkName, string newText)
{
try
{
object missingValue = Type.Missing;
object oBookmarkName = bookmarkName;
Word.Range rng = ThisDocument.Bookmarks.Item(
ref oBookmarkName).Range;
rng.Text = newText;
object oRng = rng;
ThisDocument.Bookmarks.Add(bookmarkName, ref oRng);
}
catch (Exception ex)
{
CGlobals.Logger.WriteLine(LogType.Error, ex);
}
}

Does anyone have an idea what might be the problem ?
I tried the same code on another machine with MS Office Word XP (2002)
with OffXp PIAs but no luck. What am I doing wrong ?

Thanks,

Doru
 
C

Cindy M -WordMVP-

Try get_Item. I think that's fairly standard when automating Office apps
from C#:

wd.Range rng = wdDoc.Bookmarks.get_Item(ref objBkmName).Range;

I have this configuration :WindowsXP SP2, Microsoft .NET Framework
1.1,VS.Net, MS Office Word 2003,Office 2003 Primary Interop Assemblies
(O2003PIA) and I get this error when I try to insert a text on a
bookmark.

'Microsoft.Office.Interop.Word.Bookmarks' does not contain a definition
for 'Item'

Here is the function I'm using :

private void BookMarkReplaceRange(ref Word.Document ThisDocument,
string
bookmarkName, string newText)
{
try
{
object missingValue = Type.Missing;
object oBookmarkName = bookmarkName;
Word.Range rng = ThisDocument.Bookmarks.Item(
ref oBookmarkName).Range;
rng.Text = newText;
object oRng = rng;
ThisDocument.Bookmarks.Add(bookmarkName, ref oRng);
}
catch (Exception ex)
{
CGlobals.Logger.WriteLine(LogType.Error, ex);
}
}

Does anyone have an idea what might be the problem ?
I tried the same code on another machine with MS Office Word XP (2002)
with OffXp PIAs but no luck. What am I doing wrong ?

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
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 :)
 
D

dorub

Thank you Cindy , it works just fine. The example I used works for
earlier version of MS Word.
 

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