.NETGURU
Word Document Bookmarks
Messages   Related Types
This message was discovered on microsoft.public.dotnet.framework.interop.
Responses highlighted in red are from those people who are likely to be able to contribute good, authoratitive information to this discussion. They include Microsoft employees, MVP's and others who IMHO contribute well to these kinds of discussions.
Post a new message to this list...

Andrew Thompson via .Net Guru (VIP)
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

-----------------------
Posted by a user from .Net Guru (http://www.dot-net-guru.com/)

<Id>qqyT1HV7aEiqHQo9cWXoFQ==</Id>
Reply to this message...
 
    
BBFrost
Andrew,

I'm using the Office XP PIA's
VS Net 2003
..Net Framework 1.1
Office XP (2002)

The following method is working for me. It was derived with a lot of help
from this group and a number of links including ...

http://www.microsoft.com/downloads/details.aspx?FamilyId=8B2A7288-BD98-401D-
B309-2E587D98CD67&displaylang=en
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dv_wrcore/h
tml/wroriautomatingexcelusingexcelobjectmodel.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/odc_vsto200
3_ta/html/WordObject.asp

Hope it works for your purposes.

//'---------------------------------------------------------
//' METHOD: 01/29/04
//'---------------------------------------------------------

private void ReplaceBookmarkText(Word._Document pMsWordDoc, string
pBookmarkName, string pNewText)
{
object missingValue = Type.Missing;
object oBookmarkName = pBookmarkName;

try
{
Word.Range rng = pMsWordDoc.Bookmarks.Item(ref
oBookmarkName).Range;
rng.Text = pNewText;
rng.Font.Bold = 0;
rng.Font.Color = Word.WdColor.wdColorBlue;
object oRng = rng;
pMsWordDoc.Bookmarks.Add(pBookmarkName, ref oRng);
}
catch
{
string sMsg = "\nUnknown or Unhandled bookmark encountered:
" + pBookmarkName + "\n\n";
MessageBox.Show(sMsg.ToString(),"Problem with a
bookmark:",MessageBoxButtons.OK,MessageBoxIcon.Warning);
}
}

Best wishes,

Barry
in Oregon

"Andrew Thompson via .Net Guru" <Click here to reveal e-mail address> wrote in message
news:#Click here to reveal e-mail address...
[Original message clipped]

include an Item definition.
[Original message clipped]

Reply to this message...
 
 
System.Reflection.Missing
System.Type
System.Windows.Forms.MessageBox
System.Windows.Forms.MessageBoxButtons
System.Windows.Forms.MessageBoxIcon




ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
Ad


Need Dot Net Interview Questions?
Ask ExamGuru, Inc. for advice and help on Passing .Net Interviews
.Net Projects
Best-of-breed application framework for .NET projects, developed by ExamGuru, Inc. and ExamGuru IT
Free .net Help
Commission ExamGuru, Inc. and his team for your next bespoke software project
FogBUGZ
The only bug tracking system carefully crafted with one goal in mind: helping teams create great software.
Awesome Tools
If you don't know about these, you're missing out... IT Certification Questions
IT Interview Questions
Free Oracle 10g Training
MCSE Boortcamp
Cisco Study Guides
Cheap Study Guides
Exact Questions
Dot Net Interview Questions
Oracle OCP
Cheap Travel
Designer Perfumes - Wholesale Prices
Free Programming Tutorials
 
ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
 Copyright © ExamGuru, Inc. 2001-2006
Contact Us - Terms of Use - Privacy Policy - www.dot-net-guru.com - www.examguru.net - www.oraclesource.net - www.itinterviews.net - www.examguru.net/ITCertification