Extract variables from FIle name

B

Bruce

Hi,

I have the following code that reads the context of my directory.

impdir = CurrentProject.Path & "\Import\"
strFile = (Dir(impdir & "*.csv"))

If strFile was equal to something like
strFile= "20080424 PNA.csv"

How could I extract the 20080424 as variable A and PNA as variable B. In
other words my files could be delimited by the space and the full stop in the
file name

Regards,

bruce
 
D

Douglas J. Steele

Dim strFile As String
Dim varParts As Variant

strFile= "20080424 PNA.csv"
varParts = Split(strFile, " ")

will create a two element array for you. varParts(0) will contain 20080424,
while varParts(1) will contain PNA.csv. You could get only what's before the
dot in varParts(1) using Left(varParts(1), InStr(varParts(1), ".") - 1)
 

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