Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / June 2005

Tip: Looking for answers? Try searching our database.

write some text to place where I want in word

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Pu - 27 Jun 2005 15:28 GMT
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...
Jonathan West - 27 Jun 2005 16:38 GMT
> hi,
> for example start is 14. lines and say 25. characters...
[quoted text clipped - 10 lines]
>
> 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....

Signature

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 

Pu - 28 Jun 2005 10:23 GMT
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
Jonathan West - 28 Jun 2005 10:45 GMT
In that case, is is possible that your document does not have 14 paragraphs
in it? What is the value of ActiveDocument.Range.Paragraphs.count?

Signature

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

> Hi again, thank you
> it gave that error,
[quoted text clipped - 23 lines]
>
> End Sub
Pu - 28 Jun 2005 12:04 GMT
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 :)
Jonathan West - 28 Jun 2005 12:37 GMT
> 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?

Signature

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 

Pu - 28 Jun 2005 14:26 GMT
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...
Jonathan West - 28 Jun 2005 14:40 GMT
> 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

Signature

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 

Pu - 28 Jun 2005 15:06 GMT
thank you very much, it works very well...
have a nice day...
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.