write some text to place where I want in word

P

Pu

hi,
for example start is 14. lines and say 25. characters...

I tried with;
Set myrange =
ActiveDocument.Range(Start:=ActiveDocument.Paragraphs(14).Range+25)

but it works only when I brung the cursor after from the 14.lines, and after
from the 25.characters, and saved the document like that...otherwise it
doesn't work !

may I ask whether there is a better way and / or where is my fault?

thank you and have a nice day...
 
J

Jonathan West

Pu said:
hi,
for example start is 14. lines and say 25. characters...

I tried with;
Set myrange =
ActiveDocument.Range(Start:=ActiveDocument.Paragraphs(14).Range+25)

but it works only when I brung the cursor after from the 14.lines, and
after from the 25.characters, and saved the document like that...otherwise
it doesn't work !

may I ask whether there is a better way and / or where is my fault?

thank you and have a nice day...

Try this

Set myRange = ActiveDocument.Range( _
Start:=ActiveDocument.Paragraphs(14).Range.Start + 25, _
End:=ActiveDocument.Paragraphs(14).Range.Start + 25)

You made two mistakes.

1. You didn't include an End parameter, which meant that the range would
extend to the end of the document

2. You incorrectly specified the Start parameter, not specifically
mentioning the Start property of the Range of the 14th paragraph. In the
absence of a specific property, the default property is used which is the
Text propert. Since the Text was not a number, it would have converted to
zero....


--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
 
P

Pu

Hi again, thank you
it gave that error,

"run time error 5941
the requested member of the collection doesn't exist"

when I searched in MSDN the 5941, it drives me language settings, OK my
settings didn't english US but I changed it, but no work!

that is the code

Private Sub Command1_Click()
Dim myword As Word.Application
Dim myrange As Word.Range

Set myword = CreateObject("word.application")
myword.Documents.Open "c:\qwe.doc"
myword.Visible = True
myword.Activate

Set myrange = ActiveDocument.Range( _
Start:=ActiveDocument.Paragraphs(14).Range.Start + 25, _
End:=ActiveDocument.Paragraphs(14).Range.Start + 25)

myrange.InsertBefore "abc"

End Sub
 
P

Pu

yes here is the problem,
for example its count is 1(so clean page isn't it?), how will I insert any
text to the 14. line? or isn't it possible?
also thank you for your interest :)
 
J

Jonathan West

Pu said:
yes here is the problem,
for example its count is 1(so clean page isn't it?), how will I insert any
text to the 14. line? or isn't it possible?
also thank you for your interest :)

If there aren't 14 paragraphs in the document, then any attempt to select
the 14th paragraph is doomed to failure.

It sounds as if what you are wanting to do is insert 14 paragraphs, 25
spaces and then your text into a blank document. Can you confirm this is
what you want?


--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
 
P

Pu

yes it is what I want...
I want to type text to the line 14 and 25. spaces (for example) in a blank
page...

thank you...
 
J

Jonathan West

Pu said:
yes it is what I want...
I want to type text to the line 14 and 25. spaces (for example) in a blank
page...

thank you...

Dim i As Long
With ActiveDocument.Range
For i = 1 to 14
.InsertParagraphAfter
Next i
.InsertAfter Space$(25) & "abc"
End With


--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
 

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