Range Properties Limitation?

G

George Lee

Is there a limitation to using Range's Start and End properties directly? In
the help files, the following works properly:
Set rngDoc = ActiveDocument.Range(Start:=0, End:=10)
as does
ActiveDocument.Range(Start:=0, End:=10).Bold = True

But using this in my code, I always get "Wrong number of arguments or
invalid property assignment" when using:
myString = Selection.Range(Start:=100, End:=150).Text
or
myString = whichDocument.Tables(1).Range(Start:=100, End:=150).Text
 
D

Doug Robbins - Word MVP

I would use

Dim myrange As Range
Set myrange = Selection.Range
myrange.Start = myrange.Start + 100
myrange.End = myrange.Start + 50
myrange.Bold = True

the embolden the 100th thru the 150th characters in the selection.

--
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
 
G

George Lee

Thanks. That's what I'm currently doing.

The code appears inside a Find.Execute function, so to make it work, I have
to save the Start and End separately, change the range and get the text then
reset the range. Since I'm not actually changing anything, I was hoping I
could just declare the range I want without resetting anything.
 
T

Tony Jollans

The, rather confusing, difference is because Range is a Method of a Document
and takes parameters, and a Property of the Selection which doesn't..

One way to do what you want would be something like this ...

With Selection
.document.range(.start+100, .start+150).bold=true
End With
 

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