?
Solved

Word Document Bookmarks

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

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

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

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…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

765 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