find line numbers?

E

EllenM

Hello,
I'd like to be able to find line numbers. Specifically, I'd like to find
line 3500 to use in a macro to break up a large txt file into smaller txt
files containing 3500 lines.

Thank you in advance for your help!!
Ellen
 
H

Helmut Weber

Hi Ellen,

nothing particular difficult with that,
except that the macrorecorder records
a bit different code, which I don't like too much.

Try:

Selection.GoTo _
What:=wdGoToLine, _
Which:=wdGoToAbsolute, _
Count:=3000

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
E

EllenM

Thank you Helmut!!!! I'm going to try this code.

I'd like to cut the 3500 lines into new documents until there's none left in
my original file. Could you tell me how that could be done? I assume I need
to write code with a loop that will continue creating new documents until
there's nothing left in my original file.
 
H

Helmut Weber

Hi Ellen,

like this, with lots of ways of improvewent left:

Sub Macro8()
Dim l As Long ' number of new docs to be created
Dim p As Long ' Number of paragraphs in source doc
Dim nDoc As Document ' a new doc
Dim rDcm As Range ' the source documents range
Set rDcm = ActiveDocument.Range
p = rDcm.Paragraphs.Count
While p > 1
l = l + 1
Selection.GoTo _
What:=wdGoToLine, _
Which:=wdGoToAbsolute, _
Count:=3500
rDcm.Start = 0
rDcm.End = Selection.Bookmarks("\line").Range.End
Set nDoc = Documents.Add
nDoc.Range.InsertAfter rDcm.Text
rDcm.Delete
nDoc.SaveAs Format(l, "00000") & ".doc"
nDoc.Close
Set rDcm = ActiveDocument.Range
p = rDcm.Paragraphs.Count
Wend
End Sub

HTH

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
E

EllenM

Thank you so much, Helmut!!! You've saved me SOOO much time and effort!!

Bye,
Ellen
 

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