M
mjlaali
I am developing a word automation program. In one of my methods I iterate on
sentences of a document, get the range of each sentence and in order to
select a part of the sentence, I call “MoveStart†and “MoveEnd†on the Range
object, and then I call “Select†on it to select it. But the problem is,
calling Application.GetSelection() after all of these, returns a selection
which has selected the sentence completely, and not the Range resulted after
calling “MoveStart†and “MoveEndâ€.
Another problem is if I try to change the text of the Range object, after
calling “MoveStart†and “MoveEnd†on it, using “SetText†method of the Range
results in an exception which tells “the range cannot be deletedâ€.
currentSentenceRange.MoveStart(COleVariant((short)wdCharacter),COleVariant((long)foundStartPoint)
currentSentenceRange.MoveEnd(COleVariant((short)wdCharacter),COleVariant((long)lengthDifference);
//currentSentenceRange.SetText(replacementCStr); this line causes exception
currentSentenceRange.Select();
Selection sentenceSelection = m_wordApplication.GetSelection();//the
resulted //selection has selected the sentence completely
CString selectionText = sentenceSelection.GetText();
sentenceSelection.SetText(replacementCStr);
Independent of the questions above, the whole thing I want is a method to
select and change part of a sentence. I have no problem with changing the
whole text of a sentence
sentences of a document, get the range of each sentence and in order to
select a part of the sentence, I call “MoveStart†and “MoveEnd†on the Range
object, and then I call “Select†on it to select it. But the problem is,
calling Application.GetSelection() after all of these, returns a selection
which has selected the sentence completely, and not the Range resulted after
calling “MoveStart†and “MoveEndâ€.
Another problem is if I try to change the text of the Range object, after
calling “MoveStart†and “MoveEnd†on it, using “SetText†method of the Range
results in an exception which tells “the range cannot be deletedâ€.
currentSentenceRange.MoveStart(COleVariant((short)wdCharacter),COleVariant((long)foundStartPoint)
currentSentenceRange.MoveEnd(COleVariant((short)wdCharacter),COleVariant((long)lengthDifference);
//currentSentenceRange.SetText(replacementCStr); this line causes exception
currentSentenceRange.Select();
Selection sentenceSelection = m_wordApplication.GetSelection();//the
resulted //selection has selected the sentence completely
CString selectionText = sentenceSelection.GetText();
sentenceSelection.SetText(replacementCStr);
Independent of the questions above, the whole thing I want is a method to
select and change part of a sentence. I have no problem with changing the
whole text of a sentence