is there a bug with word pictures and word.range object?

S

selim baþtürk

hi,
in a word document i find the occurence of 1.) , then the occurance of 2.)
and want to select everything within them.

int sno=wd.Content.Text.IndexOf("1.)",0);

int Ano=wd.Content.Text.IndexOf("2.)",0);

object s=sno;

object a = Ano;

MessageBox.Show(wd.Range(ref s,ref a).Text);



if there is no object between the occurences of 1.) and 2.) no problem, BUT
when there is an object (a bitmap or a clipart picture) between them, range
contains upto the object and several more characters, but not up to 2.)
Also, there is not a "2.)" occurence in rtf code of the object too...

does anyone know why can this happen? how can i fix that?!?
 
D

Doug Robbins - Word MVP

Hi Selim,

Use

Dim MyRange As Range
Set MyRange = ActiveDocument.Range
MyRange.Start = MyRange.Start + InStr(MyRange, "1.)") - 1
MyRange.End = MyRange.Start + InStr(MyRange, "2.)") + 2
MsgBox MyRange

Increase/Decrease the - 1 and the + 2 as required to eliminate the 1.) and
the 2.) if required.

--
Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP
 
S

selim bastürk

i found that when i get the text of a range, it puts a strange character for
each objects within that range. then, in range.content.text,which is a
string, length of that object is considered as 1. but in fact, the range
lenghts of those objects are not 1. so, when you get the first occurance of
the string (which is after any object) by content.text.indexof (...) , it
doesn't give the real starting point of the string.

so, a better way is using the Word.Find object to find the first occurance
of any string, it then selects that string --1.) for me-- , then
selection.range can be used to get the real range of the string, even there
is an object before that....

thx
 
C

Cindy M -WordMVP-

Hi Selim,

I explained this in answer to your duplicate original question in one of the
office.developer groups...
i found that when i get the text of a range, it puts a strange character for
each objects within that range. then, in range.content.text,which is a
string, length of that object is considered as 1. but in fact, the range
lenghts of those objects are not 1. so, when you get the first occurance of
the string (which is after any object) by content.text.indexof (...) , it
doesn't give the real starting point of the string.

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