Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
![]()
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 | |
|
|
![]() |
||||
Thread | Forum | |||
Macro to count paragraphs and save in new file | Microsoft Word Help | |||
A Macro to Save Files | Microsoft Word Help | |||
How do I count the lines with characters only? | Microsoft Word Help | |||
How do I set up Word to not count blank lines? | Microsoft Word Help | |||
Change Line Count to not count blank lines | Microsoft Word Help |