Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / November 2004

Tip: Looking for answers? Try searching our database.

Need help replacing Bookmars

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Travis Lingenfelder - 19 Nov 2004 18:59 GMT
I am creating an application that uses Word to producce reports using COM
Interop.  I have created a Word template that contains named bookmarks
everywhere I want data to be displayed.  When I execute the component in my
application that produces the report the replaced text within the bookmark is
not being displayed.

The bookmarks are being changed from a Named bookmark to a field.  If I
right-click where the bookmark sould be I can click Toggle field codes and
the data for the field is something like"{ insertedText }".

How can I get the insertedText to display properly?
Jean-Guy Marcil - 19 Nov 2004 19:09 GMT
Travis Lingenfelder was telling us:
Travis Lingenfelder nous racontait que :

> I am creating an application that uses Word to producce reports using
> COM Interop.  I have created a Word template that contains named
[quoted text clipped - 5 lines]
> I right-click where the bookmark sould be I can click Toggle field
> codes and the data for the field is something like"{ insertedText }".

It would be most helpful if you posted the relevant part of the code that
are inserting the text at the bookmarked areas.

Signature

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org

Travis Lingenfelder - 19 Nov 2004 19:51 GMT
Sorry, I meant to post the code with my previous post.

Here is the procedure to replace the text in a Named Bookmark

private void BookMarkReplaceRange(string bookmarkName, string newText)
{
 object oBookmarkName = bookmarkName;
 Word.Range rng = wrdDoc.Bookmarks.get_Item(ref oBookmarkName).Range;
 rng.Text = newText;
 object oRng = rng;
 wrdDoc.Bookmarks.Add(bookmarkName, ref oRng);
}

> Travis Lingenfelder was telling us:
> Travis Lingenfelder nous racontait que :
[quoted text clipped - 11 lines]
> It would be most helpful if you posted the relevant part of the code that
> are inserting the text at the bookmarked areas.
Chip Orange - 19 Nov 2004 19:43 GMT
It sounds like you're not updating the text in the bookmark properly.  You
should be using a line like the below (for the simplest case):

ActiveDocument.Bookmarks("MyBookMarkName").Range.Text = "new text which
overwrites the previous text"

The above however will delete the bookmark after it's updated; if you will
need to reference it by name after the update, you'll need a general purpose
subroutine for updating bookmarks which leaves them in place, like the one
below:

Public Sub UpdateBookmark(ByVal BookmarkToUpdate As String, ByVal TextToUse
As String)
   Dim BMRange As Range
   Set BMRange = ActiveDocument.Bookmarks(BookmarkToUpdate).Range
   BMRange.Text = TextToUse
   ActiveDocument.Bookmarks.Add BookmarkToUpdate, BMRange
End Sub

hth,

Chip

> I am creating an application that uses Word to producce reports using COM
> Interop.  I have created a Word template that contains named bookmarks
[quoted text clipped - 7 lines]
>
> How can I get the insertedText to display properly?
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.