MFC GoTo Bookmark Error

L

Landon

I use MFC Visual C++ 4.2.

I need to get all bookmarks in a MS Word file and update them.

I have been successful in getting all the bookmarks name but the problem is
how to update those bookmarks.

I have read from the MS Word macro that the process is to go to that
bookmark and change the value.

My code below has been successfully compiled but when it was going to be
executed, an exception was caught. The exception came from the selObj.GoTo
line. The exception stated that the bookmark does not exist.

How could it be like that? The bookmark's name was correct.

COleVariant vtBookmark( ( short ) -1 ),
vtNext ( ( short ) 2 );

CString sBookmarkName = m_Book.GetName();

selObj.GoTo( vtBookmark, vtNext, COleVariant( vtLoopVar ), sBookmarkName ) );

if( sBookmarkName == "support" )
selObj.TypeText( "123-ABC" );

How to solve it?

Thank you very much.
 
C

Cindy M.

Hi =?Utf-8?B?TGFuZG9u?=,
I use MFC Visual C++ 4.2.

I need to get all bookmarks in a MS Word file and update them.

I have been successful in getting all the bookmarks name but the problem is
how to update those bookmarks.

I have read from the MS Word macro that the process is to go to that
bookmark and change the value.
Actually, that's incorrect. The best way is to get the bookmark, then write the
data to the bookmark's range. In VBA syntax (since I have no idea about C++):
Bookmark.Range.Text = "abc"

Does that approach work better for you?

If not, where in the document are the bookmarks located that are giving you
problems?
My code below has been successfully compiled but when it was going to be
executed, an exception was caught. The exception came from the selObj.GoTo
line. The exception stated that the bookmark does not exist.

How could it be like that? The bookmark's name was correct.

COleVariant vtBookmark( ( short ) -1 ),
vtNext ( ( short ) 2 );

CString sBookmarkName = m_Book.GetName();

selObj.GoTo( vtBookmark, vtNext, COleVariant( vtLoopVar ), sBookmarkName ) );

if( sBookmarkName == "support" )
selObj.TypeText( "123-ABC" );

How to solve it?

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or reply
in the newsgroup and not by e-mail :)
 
L

Landon

Hi Cindy, thank you for your support.

I've solved it and everything has worked fine now.

Thank you
 

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