[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Word Document Bookmarks

Posted on 2004-08-21
4
Medium Priority
?
396 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

656 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