Automating msword8: Selection Extend member does not work in VC

I

Ivo Wubbels

In an existing application that communicates with Word 8 using automation I
need to make some updates; I'm having trouble to get the Extend member of
the Selection object working. The msword8.h generated file is added to my
workspace. The curSelection is a valid pointer to a Selection object.


bool AutExtendSelection(char *Text,char *szSelected)
{
curSelection->Extend(COleVariant(Text));
curSelection->Select();
CString result=curSelection->GetText();
strcpy(szSelected,result.operator LPCTSTR());
return true;
}

The idea is simple: I scan the word document for a text (works), then
trying to extend the selection (to an end marker), at the end I want to
replace the entire selection with a new text

Anybody a solution here????

Ivo
 
C

Cindy M -WordMVP-

Hi Ivo,

I don't program in your environment, so I can't make any suggestions or
comments about the approach you're trying, unsuccessfully. Nor am I clear on
what criterium you're using to extend the selection?

But I can suggest an alternative. Firstly, use the RANGE with "Find" (instead
of Selection); a successful find will reassign the found range to the Range
object variable. Then use Find again if you want to extend the selection to a
certain character. Or, if you're wanting to extend to include the entire word
or paragraph, just do, for example: obRange = objRange.Paragraphs(1).Range
In an existing application that communicates with Word 8 using automation I
need to make some updates; I'm having trouble to get the Extend member of
the Selection object working. The msword8.h generated file is added to my
workspace. The curSelection is a valid pointer to a Selection object.


bool AutExtendSelection(char *Text,char *szSelected)
{
curSelection->Extend(COleVariant(Text));
curSelection->Select();
CString result=curSelection->GetText();
strcpy(szSelected,result.operator LPCTSTR());
return true;
}

The idea is simple: I scan the word document for a text (works), then
trying to extend the selection (to an end marker), at the end I want to
replace the entire selection with a new text

Anybody a solution here????

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
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 :)
 

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