Unknow file names

  • Thread starter Thread starter s_smith_iet
  • Start date Start date
S

s_smith_iet

I am looking for a way to open up multiple files.
The files i need to open are in the following directories:
C:\Documents and Settings\Owner\My Documents\Work\P123\dat
C:\Documents and Settings\Owner\My Documents\Work\P123\txt

I want each one to open in excel so they can then be transfered to my
spread sheet so I can pull out the useful information.

The names of the files are random and always changing also I have no
idea how many will be in the folder.


Please help!!!
I am just learning VBA and have no clue what I am doing.

Thanks in advance
 
Dim WB As Workbook
Dim res As Variant
Set WB = ActiveWorkbook
ChDir "\\Stserver\st server\Debtors"
res = Application.GetOpenFilename("Xls Files (*.dat), *.xls")
If res = False Then Exit Sub

Select ALL the files you want to Open.
Corey....
I am looking for a way to open up multiple files.
The files i need to open are in the following directories:
C:\Documents and Settings\Owner\My Documents\Work\P123\dat
C:\Documents and Settings\Owner\My Documents\Work\P123\txt

I want each one to open in excel so they can then be transfered to my
spread sheet so I can pull out the useful information.

The names of the files are random and always changing also I have no
idea how many will be in the folder.


Please help!!!
I am just learning VBA and have no clue what I am doing.

Thanks in advance
 
Changing the Path to suit of course
I am looking for a way to open up multiple files.
The files i need to open are in the following directories:
C:\Documents and Settings\Owner\My Documents\Work\P123\dat
C:\Documents and Settings\Owner\My Documents\Work\P123\txt

I want each one to open in excel so they can then be transfered to my
spread sheet so I can pull out the useful information.

The names of the files are random and always changing also I have no
idea how many will be in the folder.


Please help!!!
I am just learning VBA and have no clue what I am doing.

Thanks in advance
 
Assuming you want all files to open, use the code below.
Otherwise, you can edit the ExtensionList entries for any part of the
filename that you know e.g. "*123*.txt,SomeValue*.dat"

Not sure how Excel will handle these *.dat files though. Depends on their
structure.

Private Sub CommandButton1_Click()
Dim FileName As String
Dim FileExtensions() As String
Dim i As Long

Const FolderPath As String = "C:\Documents and Settings\Owner\My
Documents\Work\P123\"
Const ExtensionList As String = "*.txt,*.dat"

FileExtensions = Split(ExtensionList, ",")
For i = LBound(FileExtensions) To UBound(FileExtensions)
FileName = Dir(FolderPath & FileExtension(i))
Do While FileName <> ""
Workbooks.Open FileName
FileName = Dir()
Loop
Next

End Sub

NickHK
 

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

Similar Threads


Back
Top