Solved

Word Document Bookmarks

Posted on 2004-08-21
4
386 Views
Last Modified: 2012-05-05
Hi,
 
I am working on a project where I need to automate MS Word and create some Documents.

I have no problems creating a word application or document object, but I do have a problem wtih the Bookmarks.

I have the following code:

                  object oMissing = System.Reflection.Missing.Value;
                  object oEndOfDoc = "\\endofdoc";
                  object oTemplate = "C:\\temp\\Invoice.dot";
                  object oBookMark = "Name";
                  
                  Word._Application oWord;
                  Word._Document oDoc;

                  oWord = new Word.Application();
                  
                  oWord.Visible = true;

                  oDoc = oWord.Documents.Add(ref oTemplate, ref oMissing, ref oMissing, ref oMissing);

                  oDoc.Bookmarks.Item(ref oBookMark).Range.Text = "TEXT GOES HERE";

However when I build my project, I get the following error:

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

Now on all the examples I have seen the above Bookmark code is used, but why do I get that error ? The Intellisense menu VS.Net pops up does not include an Item definition.

Am I not referencing something correctly ?

Thanks

Andrew
0
Comment
Question by:ttnetworks
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 10

Expert Comment

by:123654789987
ID: 11868484
I got a piece of code from MSDN for updating a BookMark text. The code is

internal void BookMarkReplaceRange(string bookmarkName, string newText)
{
    object missingValue = Type.Missing;
    object oBookmarkName = bookmarkName;
    Word.Range rng = ThisDocument.Bookmarks.get_Item(    //Here we are getting the range from an existing Bookmark.
        ref oBookmarkName).Range;                                        // Then we are reseting the text.
    rng.Text = newText;
    object oRng = rng;
    ThisDocument.Bookmarks.Add(bookmarkName, ref oRng);
}

You can refer the following article for more details

http://support.microsoft.com/default.aspx?scid=kb;EN-US;316384

Here they have asked u to add the following on top of the page

using Word = Microsoft.Office.Interop.Word;
using System.Reflection;



0
 

Author Comment

by:ttnetworks
ID: 11868510
Hi,

Yes I have read that article already, though it doesnt help much because when I compile the program I am told that Bookmarks does not contain a definition for get_Item. Which is the same error I get when using Bookmark.Item.

The using statments are already added to the class.

Andrew
0
 
LVL 4

Accepted Solution

by:
thedude112286 earned 500 total points
ID: 12011771
Try this:

...
oDoc = oWord.Documents.Add(ref oTemplate, ref oMissing, ref oMissing, ref oMissing);
oDoc.Activate();
...
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Problem to copy file 14 89
parse string in c# 5 41
Stop Git from being my repository 1 49
Change the color of spectfic dates in date picker control asp.net 29 56
Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

734 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