?
Solved

Word Document Bookmarks

Posted on 2004-08-21
4
Medium Priority
?
407 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
3 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 1000 total points
ID: 12011771
Try this:

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

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

839 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