finding Bookmarks in Header (from .NET)

J

Joe Dillon

I can access a Bookmark from my c# .net project (when the bookmark is in the main part of the word document) without a problem

BUT how can I access a Bookmark in the Header? This is the code I have tried (does not work)

object what = (int) Word.WdGoToItem.wdGoToBookmark

WordApp.ActiveWindow.ActivePane.View.SeekView = mso.Word.WdSeekView.wdSeekCurrentPageHeader
WordApp.Selection.GoTo(ref what, ref missing, ref missing, ref "MyBookMarkName" )
WordApp.Selection.TypeText( "I want to insert this value" )

The error I get is "Word cannot find the requested bookmark.

Help will be greatly appreciated
Thanks
Jo
 
D

Doug Robbins - Word MVP

Better to set the .Text property of the .Range of the bookmark rather than
selecting the bookmark

--
Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP
Joe Dillon said:
I can access a Bookmark from my c# .net project (when the bookmark is in
the main part of the word document) without a problem.
BUT how can I access a Bookmark in the Header? This is the code I have tried (does not work):

object what = (int) Word.WdGoToItem.wdGoToBookmark ;

WordApp.ActiveWindow.ActivePane.View.SeekView =
mso.Word.WdSeekView.wdSeekCurrentPageHeader ;
 
J

Joe Dillon

Many thanks Doug

The code that works is (C#)
foreach ( mso.Word.Bookmark bmk in WordApp.ActiveDocument.Bookmarks

if ( bmk.Name == (string) myBookMarkName

bmk.Range.Text = bookmarkValue



[ where:
mso = Microsoft.Office.Intero
WordApp = Microsoft.Office.Interop.Word.ApplicationClass
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top