Reformatting text

P

Peter L

I receive a report in Word and need to export to an Access database. The
problem is the record format isn't in a delimited format. Each record in
Word has the following format:

fied1 text (tab) field2 text(paragraph)
field3 text (tab) field4 text(paragraph)
field5(paragraph)
paragraph
number
paragraph
Next Record

I would like to create a macro or something so the format for each record is
something like: text, text, text, text, number so I can save as txt and
import into Access.
 
J

Jean-Guy Marcil

Peter L said:
I receive a report in Word and need to export to an Access database. The
problem is the record format isn't in a delimited format. Each record in
Word has the following format:

fied1 text (tab) field2 text(paragraph)
field3 text (tab) field4 text(paragraph)
field5(paragraph)
paragraph
number
paragraph
Next Record

I would like to create a macro or something so the format for each record is
something like: text, text, text, text, number so I can save as txt and
import into Access.

The macro could be;


Sub ReformatFields()

Dim rgeDoc As Range

Set rgeDoc = ActiveDocument.Range

With rgeDoc.Find
.Text = "(*)^t(*)^13(*)^t(*)^13(*)^13(*^13)"
.Replacement.Text = "\1,\2,\3,\4,\5,\6"
.Wrap = wdFindStop
.MatchWildcards = True
.Execute Replace:=wdReplaceAll
End With

Application.Browser.Target = wdBrowsePage

End Sub


But you could use the .Text and .Repalcement.Text parameters (from the macro
above) directly in the Find/Replace dialog box, making sure to have checked
the Wild Cards option (After clicking on the "More..." button.)
 
P

Peter L

Thank you, I'm going to give this a try.

Jean-Guy Marcil said:
The macro could be;


Sub ReformatFields()

Dim rgeDoc As Range

Set rgeDoc = ActiveDocument.Range

With rgeDoc.Find
.Text = "(*)^t(*)^13(*)^t(*)^13(*)^13(*^13)"
.Replacement.Text = "\1,\2,\3,\4,\5,\6"
.Wrap = wdFindStop
.MatchWildcards = True
.Execute Replace:=wdReplaceAll
End With

Application.Browser.Target = wdBrowsePage

End Sub


But you could use the .Text and .Repalcement.Text parameters (from the macro
above) directly in the Find/Replace dialog box, making sure to have checked
the Wild Cards option (After clicking on the "More..." button.)
 

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