From: mjlaali on 22 Feb 2010 07:52 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
From: Pesach Shelnitz on 22 Feb 2010 10:04 Hi, The problem may be in the values of the second argument that you are supplying in your calls to MoveStart and MoveEnd. If you are trying to replace a part of the sentence, the number that you supply in the second argument for MoveStart should be a positive number that is smaller than total length of the sentence, and the number that you supply in the second argument for MoveEnd should be a *negative* number which is such that the sum of its absolute value and the number supplied in the second argument for MoveStart does not exceed the total length of the sentence. If you supply a positive number in the call to MoveEnd, the Range will extend beyond the original sentence and may include a character that cannot be deleted. -- Hope this helps, Pesach Shelnitz My Web site: http://makeofficework.com "mjlaali" wrote: > 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 >
From: mjlaali on 22 Feb 2010 10:32 Hi, Thank you for your reply, but … The problem is not such as what you guessed. I have checked the arguments for validity, before calling “MoveStart” and “MoveEnd”. The Range object resulted from “MoveStart” and “MoveEnd” calls is a valid Range which is a part of the sentence and is not extended beyond the range of the original sentence. But when I call "Select" on it the resulted selection will be the complete sentence. "Pesach Shelnitz" wrote: > Hi, > > The problem may be in the values of the second argument that you are > supplying in your calls to MoveStart and MoveEnd. If you are trying to > replace a part of the sentence, the number that you supply in the second > argument for MoveStart should be a positive number that is smaller than total > length of the sentence, and the number that you supply in the second argument > for MoveEnd should be a *negative* number which is such that the sum of its > absolute value and the number supplied in the second argument for MoveStart > does not exceed the total length of the sentence. If you supply a positive > number in the call to MoveEnd, the Range will extend beyond the original > sentence and may include a character that cannot be deleted. > > -- > Hope this helps, > Pesach Shelnitz > My Web site: http://makeofficework.com > > > "mjlaali" wrote: > > > 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 > >
From: Pesach Shelnitz on 22 Feb 2010 11:51 Hi, You originally wrote that you are seeing an exception in your call to SetText. What is the error number or exact description of the exception? -- Hope this helps, Pesach Shelnitz My Web site: http://makeofficework.com "mjlaali" wrote: > Hi, > Thank you for your reply, but … > The problem is not such as what you guessed. I have checked the arguments > for validity, before calling “MoveStart” and “MoveEnd”. The Range object > resulted from “MoveStart” and “MoveEnd” calls is a valid Range which is a > part of the sentence and is not extended beyond the range of the original > sentence. But when I call "Select" on it the resulted selection will be the > complete sentence. > > > "Pesach Shelnitz" wrote: > > > Hi, > > > > The problem may be in the values of the second argument that you are > > supplying in your calls to MoveStart and MoveEnd. If you are trying to > > replace a part of the sentence, the number that you supply in the second > > argument for MoveStart should be a positive number that is smaller than total > > length of the sentence, and the number that you supply in the second argument > > for MoveEnd should be a *negative* number which is such that the sum of its > > absolute value and the number supplied in the second argument for MoveStart > > does not exceed the total length of the sentence. If you supply a positive > > number in the call to MoveEnd, the Range will extend beyond the original > > sentence and may include a character that cannot be deleted. > > > > -- > > Hope this helps, > > Pesach Shelnitz > > My Web site: http://makeofficework.com > > > > > > "mjlaali" wrote: > > > > > 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 > > >
From: mjlaali on 24 Feb 2010 06:51 Hi, As I said the exception occurs only if I use “SetText” method of the Range object itself, and its message is “the range cannot be deleted”. If you look to the code included in my first message you can see the line of code as: //currentSentenceRange.SetText(replacementCStr); this line causes //exception If I uncomment it, it will cause the exception to occur. As I said before, the “currentSentenceRange” variable includes part of a sentence Range after calling “MoveStart” and “MoveEnd”, but if I call method “Select” on it the resulting Selection object will include the complete sentence Range. "Pesach Shelnitz" wrote: > Hi, > > You originally wrote that you are seeing an exception in your call to > SetText. What is the error number or exact description of the exception? > > -- > Hope this helps, > Pesach Shelnitz > My Web site: http://makeofficework.com > > > "mjlaali" wrote: > > > Hi, > > Thank you for your reply, but … > > The problem is not such as what you guessed. I have checked the arguments > > for validity, before calling “MoveStart” and “MoveEnd”. The Range object > > resulted from “MoveStart” and “MoveEnd” calls is a valid Range which is a > > part of the sentence and is not extended beyond the range of the original > > sentence. But when I call "Select" on it the resulted selection will be the > > complete sentence. > > > > > > "Pesach Shelnitz" wrote: > > > > > Hi, > > > > > > The problem may be in the values of the second argument that you are > > > supplying in your calls to MoveStart and MoveEnd. If you are trying to > > > replace a part of the sentence, the number that you supply in the second > > > argument for MoveStart should be a positive number that is smaller than total > > > length of the sentence, and the number that you supply in the second argument > > > for MoveEnd should be a *negative* number which is such that the sum of its > > > absolute value and the number supplied in the second argument for MoveStart > > > does not exceed the total length of the sentence. If you supply a positive > > > number in the call to MoveEnd, the Range will extend beyond the original > > > sentence and may include a character that cannot be deleted. > > > > > > -- > > > Hope this helps, > > > Pesach Shelnitz > > > My Web site: http://makeofficework.com > > > > > > > > > "mjlaali" wrote: > > > > > > > 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 > > > >
|
Pages: 1 Prev: "Insert Comment" macro--can't get rid of reviewing pane Next: Calculations problem |