Login | |
|
 |
Re: Word file split - 4/16/2005 4:54:00 PM
|
|
 |
|
| |
TNO
Posts: 1075
Score: 10
Joined: 12/18/2004
From: thenewobjective.com
Status: offline
|
I'd like to take the text file and split it into multiple word documents. There are pages predefined in the text file. Are so are the desired file names.
|
|
| |
|
|
|
 |
Re: Word file split - 4/16/2005 11:14:07 PM
|
|
 |
|
| |
TNO
Posts: 1075
Score: 10
Joined: 12/18/2004
From: thenewobjective.com
Status: offline
|
Sample Text file: http://www.geocities.com/owlman5000/CMR.txt Heres the code thus far: <HTML> <HEAD> <TITLE>CMR Split</title> <HTA:APPLICATION ID = "CMR Split" APPLICATIONNAME = "CMR Split" BORDER = "thin" CAPTION = "yes" CONTEXTMENU="yes" NAVIGABLE="yes" SELECTION = "yes" SHOWINTASKBAR = "yes" SINGLEINSTANCE = "yes" SYSMENU = "yes" VERSION = "1.00" WINDOWSTATE = "maximize" > <SCRIPT LANGUAGE="JavaScript"> <!-- function blockError(){return true;} window.onerror = blockError; function whatFile() { var ForReading = 1; var fso = new ActiveXObject("Scripting.FileSystemObject"); var A = document.form1.cmuds.value; var f = fso.OpenTextFile(A, ForReading); var r = f.ReadAll(); f.close(); window.ME.value= r; } function Progress() { window.BAR.location= 'about:<html><head></head><body bgcolor="black" text="green" oncontextmenu="return false" onselectstart="return false" ondragstart="return false"><div align="center"><h3>Working<marquee direction="right" width=5%>...</marquee></h3></div></body></html>'; } function Complete() { window.BAR.location= 'about:<html><head></head><body bgcolor="black" text="green" oncontextmenu="return false" onselectstart="return false" ondragstart="return false"><div align="center"><h3>Done!</h3></div></body></html>'; } function Clear() { window.BAR.location= 'about:<html><head></head><body bgcolor="black" text="green" oncontextmenu="return false" onselectstart="return false" ondragstart="return false"></body></html>'; } // End --> </script> <SCRIPT LANGUAGE="VBScript"> <!-- dim filename filename = "CMR" 'Browse for folder Function GetFolder() Const BIF_EDITBOX = &H10 Const BIF_NEWDIALOGSTYLE = &H40 Dim sa Set sa = CreateObject("Shell.Application") Dim oF Set oF = sa.BrowseForFolder(0, "My Computer:", BIF_EDITBOX Or BIF_NEWDIALOGSTYLE) Dim fi Set fi = oF.Items.Item document.form2.FOLDER.value= fi.Path End Function 'Convert to Word Document 8pt Courier New Function Go() Const ForReading = 1 dim fso set fso = createobject("scripting.filesystemobject") dim CMR dim CMRTEXT Set CMR = fso.OpenTextFile(window.form1.cmuds.value, ForReading) CMRTEXT = CMR.ReadAll ''''''''Split according to "" (Split by page) dim CMRArray CMRArray = Split(CMRTEXT,"") dim MAXPAGE MAXPAGE = UBound(CMRArray) '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ''''For Loop here?'''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Dim MyDoc Set MyDoc = CreateObject("Word.Document") MyDoc.Application.Visible = False ' Set the font properties MyDoc.content.Font.Bold = False MyDoc.content.Font.Italic = False MyDoc.content.Font.Underline = False MyDoc.content.Font.Name = "Courier New" MyDoc.content.Font.Size = 8 'MARGINS With MyDoc.Application.ActiveDocument.PageSetup .LeftMargin = MyDoc.Application.InchesToPoints(0.7) .RightMargin = MyDoc.Application.InchesToPoints(0.7) End With ''''''''Insert CMR, but how to split? MyDoc.content.insertAfter join(CMRArray,"") MyDoc.content.InsertParagraphAfter '''''''''How to save each individual section? MyDoc.SaveAs(document.form2.FOLDER.value + "\" + filename + ".doc") MyDoc.Close Set MyDoc = Nothing set fso = nothing Complete() End Function --> </SCRIPT> </HEAD> <BODY bgcolor="black" text="green" oncontextmenu="return true" onload="Clear()"> <center> <li>Error Catching needed.... </center> <div align="center"> <p> <form name=form1>
|
|
| |
|
|
|
 |
Re: Word file split - 4/17/2005 12:31:45 AM
|
|
 |
|
| |
Snipah
Posts: 1343
Score: 6
Joined: 11/1/2004
From: Netherlands
Status: offline
|
he'd like to split 1 doc into several documents....
|
|
| |
|
|
|
 |
Re: Word file split - 4/17/2005 4:20:36 AM
|
|
 |
|
| |
Snipah
Posts: 1343
Score: 6
Joined: 11/1/2004
From: Netherlands
Status: offline
|
Are you looking for this property? PageBreak Object
|
|
| |
|
|
|
 |
Re: Word file split - 4/17/2005 9:11:43 AM
|
|
 |
|
| |
TNO
Posts: 1075
Score: 10
Joined: 12/18/2004
From: thenewobjective.com
Status: offline
|
The biggest thing I am having trouble with is figuring out how to keep each section with one another. YARM with YARM in one Doc, YADJ with YADJ, and YBAS with YBAS. Not each array element in its own file.
|
|
| |
|
|
|
 |
Re: Word file split - 4/17/2005 10:09:21 PM
|
|
 |
|
| |
TNO
Posts: 1075
Score: 10
Joined: 12/18/2004
From: thenewobjective.com
Status: offline
|
Thanks for the help. I'm close but no cigar: Function Go() Const ForReading = 1 dim fso set fso = createobject("scripting.filesystemobject") dim CMR dim CMRTEXT Set CMR = fso.OpenTextFile(window.form1.cmuds.value, ForReading) CMRTEXT = CMR.ReadAll ''''''''Split according to "" (Split by page) dim CMRArray CMRArray = Split(CMRTEXT,"") dim SectionName, Page, PageNum, PrevPageNum ''''''''Iterate through For Each Page In CMRArray SectionName = Mid(Page,497,6) PageNum = Trim(Right(Page,5)) ''''''''Create Word Document Dim MyDoc Set MyDoc = CreateObject("Word.Document") MyDoc.Application.Visible = False ' Set the font properties MyDoc.content.Font.Bold = False MyDoc.content.Font.Italic = False MyDoc.content.Font.Underline = False MyDoc.content.Font.Name = "Courier New" MyDoc.content.Font.Size = 8 'SETUP MARGINS With MyDoc.Application.ActiveDocument.PageSetup .LeftMargin = MyDoc.Application.InchesToPoints(0.7) .RightMargin = MyDoc.Application.InchesToPoints(0.7) End With ''''''''Insert Pages If PageNum > PageNumPrev Then MyDoc.content.insertAfter Page & "" MyDoc.content.InsertParagraphAfter PageNumPrev = PageNum Else '''''''''Save: MyDoc.SaveAs(document.form2.FOLDER.value + "\" + SectionName + ".doc") MyDoc.Close Set MyDoc = Nothing PageNumPrev = PageNum End If Next set fso = nothing Complete() End Function I can create all the correct file names in the array, but my logic is obviously off so I can't insert any content.
|
|
| |
|
|
|
 |
Re: Word file split - 4/19/2005 12:55:27 AM
|
|
 |
|
| |
TNO
Posts: 1075
Score: 10
Joined: 12/18/2004
From: thenewobjective.com
Status: offline
|
The Project was a success. Thank you for pointing me in the right direction. <SCRIPT LANGUAGE="VBScript"> <!-- dim filename filename = "CMR" 'Browse for folder Function GetFolder() Const BIF_EDITBOX = &H10 Const BIF_NEWDIALOGSTYLE = &H40 Dim sa Set sa = CreateObject("Shell.Application") Dim oF Set oF = sa.BrowseForFolder(0, "My Computer:", BIF_EDITBOX Or BIF_NEWDIALOGSTYLE) Dim fi Set fi = oF.Items.Item document.form2.FOLDER.value= fi.Path End Function Function Go() Const ForReading = 1 dim fso set fso = createobject("scripting.filesystemobject") dim CMR dim CMRTEXT Set CMR = fso.OpenTextFile(window.form1.cmuds.value, ForReading) CMRTEXT = CMR.ReadAll 'Split according to "" (Split by page) dim CMRArray CMRArray = Split(CMRTEXT,"") dim SectionName, Page, PageNum, PrevPageNum PrevPageNum = 0 dim MyDoc Set MyDoc = CreateObject("Word.Document") MyDoc.Application.Visible = TRUE ''''''''Iterate through For Each Page In CMRArray PageNum = Trim(Right(Page,5)) If PageNum = "" Then PageNum = 0 End If window.form1.WORKME.value = PageNum PageNum = Int(window.form1.WORKME.value) ''''''''Insert Pages If PageNum = 1 And PrevPageNum = 0 Then SectionName = Mid(Page,497,6) With MyDoc.content.Font .Bold = False .Italic = False .Underline = False .Name = "Courier New" .Size = 8 End With With MyDoc.Application.ActiveDocument.PageSetup .LeftMargin = MyDoc.Application.InchesToPoints(0.7) .RightMargin = MyDoc.Application.InchesToPoints(0.7) End With With MyDoc.content .InsertAfter Page & "" .InsertParagraphAfter End With PrevPageNum = PageNum ElseIf PageNumPrev = 1 And PageNum = 1 Then MyDoc.SaveAs(document.form2.FOLDER.value + "\" + Trim(SectionName) + ".doc") MyDoc.Close Set MyDoc = Nothing SectionName = Mid(Page,497,6) Set MyDoc = CreateObject("Word.Document") MyDoc.Application.Visible = True With MyDoc.content.Font .Bold = False .Italic = False .Underline = False .Name = "Courier New" .Size = 8 End With With MyDoc.Application.ActiveDocument.PageSetup .LeftMargin = MyDoc.Application.InchesToPoints(0.7) .RightMargin = MyDoc.Application.InchesToPoints(0.7) End With With MyDoc.content .InsertAfter Page & "" .InsertParagraphAfter End With PrevPageNum = PageNum ElseIf PageNum > PageNumPrev Then With MyDoc.content .InsertAfter Page & "" .InsertParagraphAfter End With PrevPageNum = PageNum ElseIf PageNum < PageNumPrev Then MyDoc.SaveAs(document.form2.FOLDER.value + "\" + Trim(SectionName) + ".doc") MyDoc.Close Set MyDoc = Nothing SectionName = Mid(Page,497,6) Set MyDoc = CreateObject("Word.Document") MyDoc.Application.Visible = True With MyDoc.content.Font .Bold = False .Italic = False .Underline = False .Name = "Courier New" .Size = 8 End With With MyDoc.Application.ActiveDocument.PageSetup .LeftMargin = MyDoc.Application.InchesToPoints(0.7) .RightMargin = MyDoc.Application.InchesToPoints(0.7) End With With MyDoc.content .InsertAfter Page & "" .InsertParagraphAfter End With PrevPageNum = PageNum ElseIf PageNum = 0 Then MyDoc.SaveAs(document.form2.FOLDER.value + "\" + Trim(SectionName) + ".doc") MyDoc.Close Set MyDoc = Nothing SectionName = Mid(Page,497,6) Else MsgBox(SectionName & " This page:" & PageNum & "is something not covered. The last page:" & PageNumPrev) End If PageNumPrev = PageNum Next MyDoc.Application.Quit False Set MyDoc = Nothing set fso = nothing End Function --> </SCRIPT>
|
|
| |
|
|
|
| |
|
|
 |
|
 |
|
|