VBA code to Parse Word line

P

plaintom

Hi,

I'm new to using VBA and am struggling with being able to parse a line
so I can use part of that information in the filename.

What I have are a bunch of Word files (these are doctor's patient
notes) that I need to do two things to:

1.) I need to split these files into individual files.
2.) I need the resulting filename to be have the "MRN number" "Patient
Name" "Date of visit" for the filename. (all of this information is
contained within the first three lines of these files)

For example, each file has the date as the filename and contains every
patient seen by the doctor on that date. I need this to be split so
each patient has their own file with the filename to be similar to:
'1111111 plaintom 113003.doc' and stored in a specific folder.

I have VBA code to split the files into individual patient files but
the filename is 'newdocumentx.doc' where x is a number.

Here is an example of the first three lines in each file:

CLINIC NOTE
PATIENT: LastName, FirstName CLINIC: 1234567
Doctor's Name, M.D. DATE OF VISIT: 5/30/03



Any help would be appreciated. Feel free to email me any suggestions.


Thanks,

plaintom
 
H

Helmut Weber

Hi,
getting a number or a date from a string is not a big
problem, in principle. The major problem would be, how
reliable are the criteria to identify them. If you deal
with an ordinary word-doc, not a form, there may be lots
of typing errors. Given, that there are no errors, one
simple way to get the clinic number would be:
Dim r As Range
Set r = ActiveDocument.Range
With r.Find
.ClearFormatting
.text = "<[0-9]@>" ' any word consisting of figures
.MatchWildcards = True
.Execute
End With
MsgBox r.text ' clinic
Search accordingly for:
..text = "<[0-9]{1,2}/[0-9]{1,2}/[0-9]{2}>"
that is 1 or 2 figures followed by slash
followed by 1 or 2 figures followed by slash
followed by 2 figures.
So far so good. Have the parts of the date to be
rearranged? Has there to be a leading "0"?
The Patient's name could be get form the string between
"PATIENT:" and "CLINIC:". But that is too much for
one posting.
What Word-version do you use?
Greetings from Bavaria, Germany
Helmut Weber
"red.sys" & chr$(64) & "t-online.de"
Word 97, NT 4.0
 
P

plaintom

Helmut,

Thanks for your reply. I am using Office XP (Word 2002). Any
information you can supply is appreciated.

Thanks,

Tom
 

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