J
Jason L
Hey all. I've been working on and off with a client that currently uses Wordperfect for most of their document functions. Well, since they are being asked to convert to Word, I am helping them try to get all their processes converted over. I thought I had resolved one major document process for them, but it turns out it's not working too well at all. Here is the situation.
1) File is created on an AS/400 and downloaded to a certain location on the network. It's given a rather long name like 012312213.234.doc. It's an ASCII file, I believe. Each file contains several records. These records are separated by pipes. These records need to be taken out of this format and saved into seperate files with the name of a particular field within a file.
It looks like something like this:
Field1
Field2
Field3
Field4
etc.
3) My macro grabs the third field while going to the end of record (the pipe) and saving each record in a seperate document named after this third field in each record.
4) The macro also takes each newly created file and inserts a header file at the top - this is for the merge that will later occur.
Here is the code for the first four steps:
Sub BRPTMacro()
' Updated 10/16/2003
' BRPTMacro Macro
' Macro recorded 7/18/2003 by jlogue
'This code opens the directory with the brpt file.
' It then opens the brpt file.
ChangeFileOpenDirectory "C:\wpdoc\conv\"
Documents.Open FileName:="brpt.doc"
'This code goes to the end of the file, deletes any of the garbage at the end.
Selection.EndKey Unit:=wdStory
Selection.TypeBackspace
Selection.TypeBackspace
' This code finds all commas and replaces them with asterisks. This is because I used commas
' as field delimiters.
'This code finds each tilda and replaces it with a line break.
With Selection.Find
.Text = "^w~"
.Replacement.Text = "~"
.Forward = True
.Wrap = wdFindContinue
End With
Selection.Find.Execute Replace:=wdReplaceAll
With Selection.Find
.Text = "~"
.Replacement.Text = "^l"
.Forward = True
.Wrap = wdFindContinue
End With
Selection.Find.Execute Replace:=wdReplaceAll
With Selection.Find
.Text = "|"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
End With
Selection.Find.Execute Replace:=wdReplaceAll
'The following code finds the certain code number in the document by looking for
' the sixth line down. It then moves over 12 character units and selects the entire
' number.
Dim fname As String, i As Integer, Source As Document, Target As Document
Set Source = ActiveDocument
For i = 1 To Source.Paragraphs.Count
Set Target = Documents.Add
Target.Range = Source.Paragraphs(i).Range
Selection.Find.Execute Replace:=wdReplaceAll
Selection.HomeKey Unit:=wdStory, Extend:=wdExtend
Selection.MoveDown Unit:=wdLine, Count:=6
Selection.MoveRight Unit:=wdCharacter, Count:=12, Extend:=wdExtend
fname = Selection
'After the files are separated, this code inserts the field files at the beginning
' and ending of each file.
Selection.HomeKey Unit:=wdStory
Selection.InsertFile FileName:="C:\wpdoc\conv\Fields2.doc"
Selection.EndKey Unit:=wdStory
Selection.TypeBackspace
Selection.InsertFile FileName:="C:\wpdoc\conv\Fields3.doc"
Selection.EndKey Unit:=wdStory
Selection.TypeBackspace
'This code saves the file according to the variable above (fname), and it stores it into
' the path below. To change where this file is saved, simply change the path.
Target.SaveAs FileName:="C:\wpdoc\conv\" & fname & ".doc"
Target.Close
Set Target = Nothing
Next i
Set Source = Nothing
ActiveDocument.Close SaveChanges = True
End Sub
5) Each newly created file also has another document inserted at the end called the Comments doc. This is a file containing more fields that have comments attached to each field. These comments are used to instruct the users on what information should be inserted. I made these fields into Macrobutton fields so they would only need to click and enter info.
6) After all the files are separated and saved, a user will typically open the document and enter information in the comment fields. He/she then takes the files and clicks another macro that converts the data into a merge source, opens the merge document and merges the data into the form. If this works successfully, woo hoo! Usually there are a ton of formatting problems and when they insert tables into a field, the table doesn't get merged correctly.
7) Here is my favorite part. After this file is merged a form, all the comments are naturally removed, but this same file needs to be used and added to by countless other people in different departments. People will need to open the files and use the comments to see where to add their information for their own forms.
To tell you the truth, I'm amazed it worked for awhile. The conversion and saving of the seperate files worked really well in my macro, but when users would need to interact with the comments fields, etc., and then use it again as a data source, well, that's where I got into trouble. It just became very complicated for new Word users.
I am open to using a mixture of Access, Excel and Word if anyone thinks it would help. These users are being asked to stop using Wordperfect by the end of the year, so they really need a workable solution. If you search my name, you will see that I've talked a lot about this issue in the past.
Thanks for any help you can give.
-Jason
1) File is created on an AS/400 and downloaded to a certain location on the network. It's given a rather long name like 012312213.234.doc. It's an ASCII file, I believe. Each file contains several records. These records are separated by pipes. These records need to be taken out of this format and saved into seperate files with the name of a particular field within a file.
It looks like something like this:
Field1
Field2
Field3
Field4
etc.
3) My macro grabs the third field while going to the end of record (the pipe) and saving each record in a seperate document named after this third field in each record.
4) The macro also takes each newly created file and inserts a header file at the top - this is for the merge that will later occur.
Here is the code for the first four steps:
Sub BRPTMacro()
' Updated 10/16/2003
' BRPTMacro Macro
' Macro recorded 7/18/2003 by jlogue
'This code opens the directory with the brpt file.
' It then opens the brpt file.
ChangeFileOpenDirectory "C:\wpdoc\conv\"
Documents.Open FileName:="brpt.doc"
'This code goes to the end of the file, deletes any of the garbage at the end.
Selection.EndKey Unit:=wdStory
Selection.TypeBackspace
Selection.TypeBackspace
' This code finds all commas and replaces them with asterisks. This is because I used commas
' as field delimiters.
'This code finds each tilda and replaces it with a line break.
With Selection.Find
.Text = "^w~"
.Replacement.Text = "~"
.Forward = True
.Wrap = wdFindContinue
End With
Selection.Find.Execute Replace:=wdReplaceAll
With Selection.Find
.Text = "~"
.Replacement.Text = "^l"
.Forward = True
.Wrap = wdFindContinue
End With
Selection.Find.Execute Replace:=wdReplaceAll
With Selection.Find
.Text = "|"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
End With
Selection.Find.Execute Replace:=wdReplaceAll
'The following code finds the certain code number in the document by looking for
' the sixth line down. It then moves over 12 character units and selects the entire
' number.
Dim fname As String, i As Integer, Source As Document, Target As Document
Set Source = ActiveDocument
For i = 1 To Source.Paragraphs.Count
Set Target = Documents.Add
Target.Range = Source.Paragraphs(i).Range
Selection.Find.Execute Replace:=wdReplaceAll
Selection.HomeKey Unit:=wdStory, Extend:=wdExtend
Selection.MoveDown Unit:=wdLine, Count:=6
Selection.MoveRight Unit:=wdCharacter, Count:=12, Extend:=wdExtend
fname = Selection
'After the files are separated, this code inserts the field files at the beginning
' and ending of each file.
Selection.HomeKey Unit:=wdStory
Selection.InsertFile FileName:="C:\wpdoc\conv\Fields2.doc"
Selection.EndKey Unit:=wdStory
Selection.TypeBackspace
Selection.InsertFile FileName:="C:\wpdoc\conv\Fields3.doc"
Selection.EndKey Unit:=wdStory
Selection.TypeBackspace
'This code saves the file according to the variable above (fname), and it stores it into
' the path below. To change where this file is saved, simply change the path.
Target.SaveAs FileName:="C:\wpdoc\conv\" & fname & ".doc"
Target.Close
Set Target = Nothing
Next i
Set Source = Nothing
ActiveDocument.Close SaveChanges = True
End Sub
5) Each newly created file also has another document inserted at the end called the Comments doc. This is a file containing more fields that have comments attached to each field. These comments are used to instruct the users on what information should be inserted. I made these fields into Macrobutton fields so they would only need to click and enter info.
6) After all the files are separated and saved, a user will typically open the document and enter information in the comment fields. He/she then takes the files and clicks another macro that converts the data into a merge source, opens the merge document and merges the data into the form. If this works successfully, woo hoo! Usually there are a ton of formatting problems and when they insert tables into a field, the table doesn't get merged correctly.
7) Here is my favorite part. After this file is merged a form, all the comments are naturally removed, but this same file needs to be used and added to by countless other people in different departments. People will need to open the files and use the comments to see where to add their information for their own forms.
To tell you the truth, I'm amazed it worked for awhile. The conversion and saving of the seperate files worked really well in my macro, but when users would need to interact with the comments fields, etc., and then use it again as a data source, well, that's where I got into trouble. It just became very complicated for new Word users.
I am open to using a mixture of Access, Excel and Word if anyone thinks it would help. These users are being asked to stop using Wordperfect by the end of the year, so they really need a workable solution. If you search my name, you will see that I've talked a lot about this issue in the past.
Thanks for any help you can give.
-Jason