View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Bob Phillips[_6_] Bob Phillips[_6_] is offline
external usenet poster
 
Posts: 11,272
Default Parse Directory Filenames

Append this to your code

Columns("A:A").Copy Range("B1")
Columns("B:B").TextToColumns Destination:=Range("B1"), _
DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, _
ConsecutiveDelimiter:=False, _
Tab:=True, _
Semicolon:=False, _
Comma:=True, _
Space:=False, Other:=False, _
FieldInfo:=Array(Array(1, 1), Array(2, 1),
Array(3, 1))


--

HTH

RP
(remove nothere from the email address if mailing direct)


"chrisjnorskov"
wrote in message
news:chrisjnorskov.1ts6qi_1124067998.5826@excelfor um-nospam.com...

Hello all,


I am stuck and was hoping some of the experts out there in the forum
could give me a hand.

First, let me explain what I am trying to accomplish:


I have a directory (C:\Home) that has hundreds of files in it.

They are medical transcription files in Word format and are named as
such:


12345,Doe John,Ltr.doc

67890,Doe Jane,Pro.doc


The first string of 5 characters is the medical record.
The second string is the patient name.
The third is what type of document this is (Ltr being Letter, Pro being
Progress Note, etc)


What I am trying to do is:

1. Parse directory and populate A1 with result.
2. Parse filenames, put medical record number in B1
3. Parse filenames, put patient name in C1
4. Parse filenames, put document type in D1

- If Ltr is found, "Letter" is inserted into D1
- If Pro is found, "Progress Note" is inserted into D1


Below is my code, I have gotten as far as 1. in the list above.

Any help would be very much appreciated!


Sub PARSE()
Dim fs, f, f1, f2
Range("A1").Select
i = 1
fldr = "C:\home\"
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.getfolder(fldr)
Set f1 = f.Files
For Each f2 In f1
ActiveCell.Offset(i, 0).Value = f2.Name
i = i + 1

Next
End Sub





thank you,

Chris


--
chrisjnorskov
------------------------------------------------------------------------
chrisjnorskov's Profile:

http://www.excelforum.com/member.php...o&userid=26286
View this thread: http://www.excelforum.com/showthread...hreadid=395707