Opening files by VBA

G

Guest

Hello,

I want to open Excel-files (one by one) that are in a certain directory.
With the opened files I want to do some calculations by means of a VBA macro
which is stored in a already opened workbook. After the calculations the
files are closed again.

How do I manage to open the files one by one from the macro?

An answer to this would be very helpful...
 
B

Bob Phillips

Dim sFile As String
sFile = Dir("C:\TestFolders\*.xls", vbNormal)
If sFile <> "" Then
Do
'do your stuff
Debug.Print sFile
sFile = Dir
Loop Until sFile = ""
End If


--
---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)
 
G

Guest

Thanx Bob, works perfect!

Bob Phillips said:
Dim sFile As String
sFile = Dir("C:\TestFolders\*.xls", vbNormal)
If sFile <> "" Then
Do
'do your stuff
Debug.Print sFile
sFile = Dir
Loop Until sFile = ""
End If


--
---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)
 

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