Reply
 
Thread Tools Display Modes
  #1   Report Post  
Posted to microsoft.public.word.docmanagement
JR JR is offline
external usenet poster
 
Posts: 29
Default Macro to count lines and save in differents files

Hi all,

How to make a Macro to count 20 lines in a text with 3000 lines and save
every 20 lines in new file with total 150 new arquives starting in
File000.doc, file001.doc.., File150.doc?

I´ve tried to put a text with 2000 lines in word 2003 and start macro
count line 1 to line 20, file save as give a name file000.doc, start again
in line 21 go to line 40 filesave as give a name file001.doc. But nothing
work, this macro don't save the file.

Thank´s in advanced

jr
  #2   Report Post  
Posted to microsoft.public.word.docmanagement
Doug Robbins - Word MVP Doug Robbins - Word MVP is offline
external usenet poster
 
Posts: 8,832
Default Macro to count lines and save in differents files

If these are just lines rather than paragraphs, there is a problem because
lines do not mean very much in Word.

If each line is actually a separate paragraph, then something like the
following would do it:

Dim i As Long
Dim Source As Document, target As Document
Dim arnge As Range
i = 0
For i = 0 To 150
Set Source = ActiveDocument
Set arnge = Source.Range
arnge.Start = Source.Range.Start
arnge.End = Source.Paragraphs(20).Range.End
Set target = Documents.Add
target.Range.FormattedText = arnge.FormattedText
target.SaveAs "C:\Test\File" & Format(i, "000")
target.Close
arnge.Delete
Next i

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

"Jr" wrote in message
...
Hi all,

How to make a Macro to count 20 lines in a text with 3000 lines and save
every 20 lines in new file with total 150 new arquives starting in
File000.doc, file001.doc.., File150.doc?

I´ve tried to put a text with 2000 lines in word 2003 and start macro
count line 1 to line 20, file save as give a name file000.doc, start again
in line 21 go to line 40 filesave as give a name file001.doc. But nothing
work, this macro don't save the file.

Thank´s in advanced

jr



  #3   Report Post  
Posted to microsoft.public.word.docmanagement
JR JR is offline
external usenet poster
 
Posts: 29
Default Macro to count lines and save in differents files

Mr. Doug,

Thank you to help me.

The problem is to cut a text around 2000 or 3000 LINES (not paragraph)
indepent if line is blanck or not and save in a different files.

Example:

Open a text name GURU.doc

This text GURU.doc have 60 lines.

Cut this text and save this in number of files that contain 20 line each.

GURU01.doc start at line 00 and finish at line 20


GURU02.doc start at line 21 and finish at line 40


GURU03.doc start at line 40 and finish at line 59

Thank's in advanced

"Doug Robbins - Word MVP" wrote:

If these are just lines rather than paragraphs, there is a problem because
lines do not mean very much in Word.

If each line is actually a separate paragraph, then something like the
following would do it:

Dim i As Long
Dim Source As Document, target As Document
Dim arnge As Range
i = 0
For i = 0 To 150
Set Source = ActiveDocument
Set arnge = Source.Range
arnge.Start = Source.Range.Start
arnge.End = Source.Paragraphs(20).Range.End
Set target = Documents.Add
target.Range.FormattedText = arnge.FormattedText
target.SaveAs "C:\Test\File" & Format(i, "000")
target.Close
arnge.Delete
Next i

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

"Jr" wrote in message
...
Hi all,

How to make a Macro to count 20 lines in a text with 3000 lines and save
every 20 lines in new file with total 150 new arquives starting in
File000.doc, file001.doc.., File150.doc?

I´ve tried to put a text with 2000 lines in word 2003 and start macro
count line 1 to line 20, file save as give a name file000.doc, start again
in line 21 go to line 40 filesave as give a name file001.doc. But nothing
work, this macro don't save the file.

Thank´s in advanced

jr




  #4   Report Post  
Posted to microsoft.public.word.docmanagement
Doug Robbins - Word MVP Doug Robbins - Word MVP is offline
external usenet poster
 
Posts: 8,832
Default Macro to count lines and save in differents files

Try this:

Dim Totallines As Long
Dim Source As Document, Target As Document
Dim crange As Range
Set Source = ActiveDocument
Totallines = Source.Range.ComputeStatistics(wdStatisticLines)
lines = InputBox("Enter the number of lines that you want in each file")
If IsNumeric(lines) Then
For i = 1 To Int(Totallines / lines)
Source.Activate
Selection.HomeKey wdStory
Selection.MoveDown wdLine, lines, wdExtend
Set crange = Selection.Range
Set Target = Documents.Add
Target.Range.FormattedText = crange.FormattedText
Target.SaveAs "Document" & i
Target.Close
crange.Cut
Next i
Source.SaveAs "Document" & i + 1
Else
MsgBox "You must enter a whole number."
End If



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

"Jr" wrote in message
news
Mr. Doug,

Thank you to help me.

The problem is to cut a text around 2000 or 3000 LINES (not paragraph)
indepent if line is blanck or not and save in a different files.

Example:

Open a text name GURU.doc

This text GURU.doc have 60 lines.

Cut this text and save this in number of files that contain 20 line each.

GURU01.doc start at line 00 and finish at line 20


GURU02.doc start at line 21 and finish at line 40


GURU03.doc start at line 40 and finish at line 59

Thank's in advanced

"Doug Robbins - Word MVP" wrote:

If these are just lines rather than paragraphs, there is a problem
because
lines do not mean very much in Word.

If each line is actually a separate paragraph, then something like the
following would do it:

Dim i As Long
Dim Source As Document, target As Document
Dim arnge As Range
i = 0
For i = 0 To 150
Set Source = ActiveDocument
Set arnge = Source.Range
arnge.Start = Source.Range.Start
arnge.End = Source.Paragraphs(20).Range.End
Set target = Documents.Add
target.Range.FormattedText = arnge.FormattedText
target.SaveAs "C:\Test\File" & Format(i, "000")
target.Close
arnge.Delete
Next i

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

"Jr" wrote in message
...
Hi all,

How to make a Macro to count 20 lines in a text with 3000 lines and
save
every 20 lines in new file with total 150 new arquives starting in
File000.doc, file001.doc.., File150.doc?

I´ve tried to put a text with 2000 lines in word 2003 and start macro
count line 1 to line 20, file save as give a name file000.doc, start
again
in line 21 go to line 40 filesave as give a name file001.doc. But
nothing
work, this macro don't save the file.

Thank´s in advanced

jr






  #5   Report Post  
Posted to microsoft.public.word.docmanagement
JR JR is offline
external usenet poster
 
Posts: 29
Default Macro to count lines and save in differents files

Hi!

I´ll try today and post the results tomorrow.

Thank´s for your help.

Jr

"Doug Robbins - Word MVP" escreveu:

Try this:

Dim Totallines As Long
Dim Source As Document, Target As Document
Dim crange As Range
Set Source = ActiveDocument
Totallines = Source.Range.ComputeStatistics(wdStatisticLines)
lines = InputBox("Enter the number of lines that you want in each file")
If IsNumeric(lines) Then
For i = 1 To Int(Totallines / lines)
Source.Activate
Selection.HomeKey wdStory
Selection.MoveDown wdLine, lines, wdExtend
Set crange = Selection.Range
Set Target = Documents.Add
Target.Range.FormattedText = crange.FormattedText
Target.SaveAs "Document" & i
Target.Close
crange.Cut
Next i
Source.SaveAs "Document" & i + 1
Else
MsgBox "You must enter a whole number."
End If



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

"Jr" wrote in message
news
Mr. Doug,

Thank you to help me.

The problem is to cut a text around 2000 or 3000 LINES (not paragraph)
indepent if line is blanck or not and save in a different files.

Example:

Open a text name GURU.doc

This text GURU.doc have 60 lines.

Cut this text and save this in number of files that contain 20 line each.

GURU01.doc start at line 00 and finish at line 20


GURU02.doc start at line 21 and finish at line 40


GURU03.doc start at line 40 and finish at line 59

Thank's in advanced

"Doug Robbins - Word MVP" wrote:

If these are just lines rather than paragraphs, there is a problem
because
lines do not mean very much in Word.

If each line is actually a separate paragraph, then something like the
following would do it:

Dim i As Long
Dim Source As Document, target As Document
Dim arnge As Range
i = 0
For i = 0 To 150
Set Source = ActiveDocument
Set arnge = Source.Range
arnge.Start = Source.Range.Start
arnge.End = Source.Paragraphs(20).Range.End
Set target = Documents.Add
target.Range.FormattedText = arnge.FormattedText
target.SaveAs "C:\Test\File" & Format(i, "000")
target.Close
arnge.Delete
Next i

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

"Jr" wrote in message
...
Hi all,

How to make a Macro to count 20 lines in a text with 3000 lines and
save
every 20 lines in new file with total 150 new arquives starting in
File000.doc, file001.doc.., File150.doc?

I´ve tried to put a text with 2000 lines in word 2003 and start macro
count line 1 to line 20, file save as give a name file000.doc, start
again
in line 21 go to line 40 filesave as give a name file001.doc. But
nothing
work, this macro don't save the file.

Thank´s in advanced

jr






Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro to count paragraphs and save in new file Jr Microsoft Word Help 2 May 2nd 07 03:13 AM
A Macro to Save Files JeanneJo Microsoft Word Help 8 April 4th 07 06:46 AM
How do I count the lines with characters only? Shannon Microsoft Word Help 2 July 21st 06 11:56 AM
How do I set up Word to not count blank lines? Don't want to count blank lines. Microsoft Word Help 2 October 30th 05 03:10 PM
Change Line Count to not count blank lines Carol Microsoft Word Help 4 November 27th 04 01:46 PM


All times are GMT +1. The time now is 08:46 PM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"