Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

getting datas of each workbooks in directory

Status
Not open for further replies.

damrus

Technical User
Jun 22, 2008
24
PL
Hi!
I need to get some datas from each workbooks in directory.
How to do it?
For example: I need to get value from cell "A1" of each workbooks in directory.

Regards
 
damrus, what code do you have so far?


Never knock on Death's door: ring the bell and run away! Death really hates that!
 
Actually I have any code. I have no idea how to do it.
How to connect with another workbook without opening it and how to search chosen directory?
 
Searching files and folders take a look at the File System Object

then maybe DAO/ADO to connect / open the workbooks.

Never knock on Death's door: ring the bell and run away! Death really hates that!
 




Is this a ONE TIME thing?

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
No, I do sth monthly. Each month one workbook is added into directory.
Simply I need to do loop until last file.xls in chosen directory. - this is one thing.
Secondly I need to get sth from each workbooks, so I need to connect with each workbook in one step of loop and for example get cell(1,1).

1) How to define last file in directory(ie C:\Directory\) ?
2) How to connect with each excell file and get ie cells(1,1)

 
Why does it work in excell 2000 and doesn't work in excell 2007?
Error 445 is generated
- object doesn't support this action.

Sub searchf()

Set fs = Application.FileSearch
With fs
.LookIn = "E:\Dane\Tym\"
.Filename = "*.*"
If .Execute > 0 Then
MsgBox "There were " & .FoundFiles.Count & _
" file(s) found."
For i = 1 To .FoundFiles.Count
MsgBox .FoundFiles(i)
Next i
Else
MsgBox "There were no files found."
End If
End With
End Sub
 




error on exactly what statment?

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 




What happens is your do this...
Code:
Sub searchf()

With Application.FileSearch
    .LookIn = "E:\Dane\Tym\"
'.......

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
The same error on

With Application.FileSearch
 
It appears that Filesearch has been dropped from Access 2007. Check out this link for the work-around using Dir or the FileSystemObject.
 




FileSearch appears NOT to be available in Excel 2007.

Did you try the FileSystemObject? as previously suggested?

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
But I have still some problems.
How to get in this code name of each file?

Sub SearchF()
Dim fso As New FileSystemObject
Dim fld As Folder, f As File
Dim path As String, i As Long
path = "E:\Dane\Tym\"
Set fld = fso.GetFolder(path)
For i = 1 To fld.Files.Count
Debug.Print fld.Files.Count
' how to get file name?
Next
End Sub
 
Code:
For i = 1 To fld.Files.Count
    Debug.Print fld.Files.Count
    Debug.Print fld.Files(i).Name
Next
or
Code:
For Each f in fld.Files
   Debug.Print f.Name
Next
 




Code:
Sub SearchF()
    Dim fso As Object
    Dim fld As Object, fil As Object
    
    Set fso = CreateObject("Scripting.FileSystemObject")
    Dim path As String, i As Long
    path = "C:\"
    Set fld = fso.GetFolder(path)
    
    For Each fil In fld.Files
        Debug.Print fil.Name
    Next
End Sub

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Golom,
second code works:), but I'm wondering why in first code error occurs:
Invalid procedure call or argument
on Debug.Print fld.Files(i).Name

It can be useful if you want do sth with ie file(3)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top