select problem because of shape

L

levan82

I have such a problem
I usually select text in document this way
ActiveDocument.Range(start:=7,end:=8).select
but when there is any shape in this document on the same line with the
text, selection doesnt work :(
what's the problem? please help me if you can

thanks in advance
 
J

Jezebel

It's hard to offer a solution without knowing the question. What are you
actually trying to do? How does your code know what to select, and why?
 
L

levan82

thanks for reply
whole code of program is very large and is not important for this
problem so I'll tell you little part in which I have problem exactly
what I trying to do is to select some range of text

for example:
Private Sub CommandButton4_Click()

ActiveDocument.Range(7, 8).Select

End Sub

it works when there is only text in document, but when there is some
shape for example "line" this range doesn't select

I give you the link http://rapidshare.com/files/13765533/
EMA1_.doc.html

from this link you can download .doc file in which I have problem, so
please if you can take a look at it
I want to select '#' symbol there and it selects with code above,
only after I delete the 'line' on the right
hope and waitting for your reply

thanks a lot in advance
 
J

Jezebel

That really doesn't explain much. What are you actually trying to select?
Why are you working with the Selection object at all? Normally the selection
object is useful only if you are communicating directly with the user; in
which case your problem seems arse-about.

You can check if a range has a shape in it by checking the
InlineShapes.Count property; or you can look at the content of the range: an
inline shape is represented by chr(1).
 
L

levan82

I said, I want to select text range. because then I need to change
this selection with other text
this way :

Selection.TypeText Text:="some text" and when there is no selection I
cannot do that

thanks for your replies
 
D

Doug Robbins - Word MVP

You do NOT have to select the text range to change it.

ActiveDocument.Range(7, 8).Text = "some other text"


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
J

Jay Freedman

And usually it works better to use a Find instead of trying to nail
down exact start and end values. This is a sample, and there are many
ways to enhance it:

Set myRange = Selection.Range
With myRange.Find
.ClearFormatting
.Text = "some text"
.Replacement.Text = "some other text"
.Execute
End With

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.
 
L

levan82

no, no, no
no I dont want only change the range text I know how to do it without
select
I want exactly what I said: "I want to select text range" for working
with user also

so if you can help me with selecting text with shapes it would be nice
 
L

levan82

my program at which I am working is very difficult and large so this
problem is a part of big code and I dont want only changing range for
some reasons I want to select text and also for changing it but not
only for that

so help me to select text range which contains some shape it doesnt
work this way

thanks
 
D

Doug Robbins - Word MVP

There are some things that you can do through the user interface and what
you are trying to do - use code to select items in different Stories - is
not possible.

For another example of how differently things must be done with code, use
the macro recorder to record replacing something in a header and compare
what is recorded with how you have to do it with code in thearticle "Using a
macro to replace text where ever it appears in a document including Headers,
Footers, Textboxes, etc." at:

http://www.word.mvps.org/FAQs/MacrosVBA/FindReplaceAllWithVBA.htm


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
L

levan82

I just tried to change range text with shape after this range, I did
it as you said:
ActiveDocument.Range(7, 8).Text = "some other text"
but it did the same not changed the text but inserts the text :"some
other text" before that range

as I get I cannot change the range text if there is any shape in
paragraph
 
J

Jezebel

The fact that your program is large and badly designed is a pity; but the
sooner you recognise that you f***ed up and fix it properly, the better. As
your problem demonstrates, the method you've used leads to a program that's
full of bugs.
 
L

levan82

listen "Jezebel" if you cannot help in solving the problem stay still
and dont demonstrate f***ing knowledge
 
J

Jezebel

You've been offered several solutions to your problem. The fact that you
don't like them is no-one else's problem.

If you've written a large app that manipulates documents using Selection and
TypeText, you're going to be chasing bugs till the cows come home. The
problem you have with shapes will also manifest with any number of other
object types, which you are -- it seems -- yet to encounter (fields and
footnotes to name but two).

This was a sad programming blulnder on your part, and the solution to your
problem is to admit that mistake and fix it. But I suspect that you lack the
moral integrity for that.
 
L

levan82

it seems my program and its problem bothers you more than me :))
and you know more than I about my program and its code :)

you think you gave me solution?? :)) dont be so funny

dont you think you take much more upon yourself than you can?
so once more, dont bother yourself very much if you cant help
 
D

Doug Robbins - Word MVP

That is almost certainly for the reason that I mentioned.

Did you even bother to explore the information and the link to which I
directed you?

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
L

levan82

thanks for link but
I know how to change text with find and raplace but it's not useful in
my case, because I am not only changing text
thanks anyway for trying to help ;)
 
D

Doug Robbins - Word MVP

I did not direct you to that site because I thought that you were just
changing text. It was in an (apparently futile) attempt to get you to see
that it is not always straightforward, and sometimes might even not be
possible to do with vba the same thing that you can do throught the user
interface.

I suggest that you remove the blinkers.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 

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