Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default Script for Retrieving Data

Afternoon Guys,

I'm trying to create a script that would allow me to retrieve data of
multiplies excel in any folder.

example. in folder A (c:\folder A\), there is 2 folder (B and D), each of
these folders have 5 excel spreadsheet in them. i want a script that will
collect information of all spreadsheet located in all folders under folder A.
The cell that the information is received from is cell,A1 on sheet
'Scorecard'. The current scrip that i have allows me to gather all
spreadsheet located in 1 folder, not several folders.

The script below is the one currently in use but is only limited to one
folder (A). I want to modify it so that it includes all the folder (B & D) in
that one folder (A) directory.

Sub get_data()

Dim fs, f, f1, fc
Dim row_num As Integer
Dim folder As String
Dim response As Integer
Dim Start As Single, Finish As Single, TotalTime As Single
Dim filename As String

folder = ActiveWorkbook.Path & "\"
row_num = 3

Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFolder(folder)
Set fc = f.Files
response = MsgBox("Collecting scorecards data may take some time. Please be
patient", vbOKCancel, "Continue?")

Sheets("Index").Range("H1").Value = 0
Sheets("Index").Range("I1").Value = 0

If (response = 1) Then
Start = Timer ' Set start time.

Sheets("Scorecard Data").Visible = True
Sheets("Scorecard Data").Select
Columns("GE:GG").Select
Selection.ClearContents
Sheets("Scorecard Data").Visible = True

Sheets("Scorecard Targets").Visible = True
Sheets("Scorecard Targets").Select
Columns("GE:GG").Select
Selection.ClearContents
Sheets("Scorecard Data").Visible = True


For Each f1 In fc
If (f1 < ActiveWorkbook.Path & "\" & ActiveWorkbook.Name) Then
Sheets("Index").Range("I1").Value =
Sheets("Index").Range("I1").Value + 1
End If
Next
For Each f1 In fc
If (f1 < ActiveWorkbook.Path & "\" & ActiveWorkbook.Name) Then
Sheets("Index").Range("H1").Value =
Sheets("Index").Range("H1").Value + 1

filename = f1.Name

Sheets("Scorecard Data").Range("GE" & row_num).Value = "='" & _
folder & "[" & filename & "]Scorecard'!A1"
Sheets("Scorecard Targets").Range("GE" & row_num).Value = "='" & _
folder & "[" & filename & "]Scorecard'!A2"
Sheets("Scorecard Target To Date").Range("GE" & row_num).Value =
"='" & _
folder & "[" & filename & "]Scorecard'!B2"
Sheets("Scorecard Data").Range("GG" & row_num).Value = folder &
filename

row_num = row_num + 1

End If
Next

row_num = 3

Finish = Timer ' Set end time.
TotalTime = Finish - Start ' Calculate total time.

MsgBox "" & Sheets("Index").Range("I1").Value & " Scorecards Gathered in " &
Round(TotalTime) & " seconds.", vbOKOnly, "Completed"

Sheets("Index").Range("E1").Value = Now

End If

End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
Tim Tim is offline
external usenet poster
 
Posts: 145
Default Script for Retrieving Data

Typically you would do this using recursion

Eg (pseudocode/untested)

Sub StartHere()
ProcessFolders "C:\someinitalfolder"
End sub

Sub ProcessFolder(sPath)
set sht=thisworkbook.sheets("listing")
set fso=createobject("Scripting.FileSystemObject")
set fold=fso.GetFolder(sPath)

'get first unused row in col A
r=sht.Cells(sht.rows.count,1).end(xlup).row+1

for each f in fold.Files
'record details of f
sht.Cells(r,1).value=f.path
next f

'now call this procedure on each subfolder
for each sf in fold.subfolders
ProcessFolder fold.Path
next sf

end sub



Tim



"chinny" wrote in message
...
Afternoon Guys,

I'm trying to create a script that would allow me to retrieve data of
multiplies excel in any folder.

example. in folder A (c:\folder A\), there is 2 folder (B and D), each of
these folders have 5 excel spreadsheet in them. i want a script that will
collect information of all spreadsheet located in all folders under folder
A.
The cell that the information is received from is cell,A1 on sheet
'Scorecard'. The current scrip that i have allows me to gather all
spreadsheet located in 1 folder, not several folders.

The script below is the one currently in use but is only limited to one
folder (A). I want to modify it so that it includes all the folder (B & D)
in
that one folder (A) directory.

Sub get_data()

Dim fs, f, f1, fc
Dim row_num As Integer
Dim folder As String
Dim response As Integer
Dim Start As Single, Finish As Single, TotalTime As Single
Dim filename As String

folder = ActiveWorkbook.Path & "\"
row_num = 3

Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFolder(folder)
Set fc = f.Files
response = MsgBox("Collecting scorecards data may take some time. Please
be
patient", vbOKCancel, "Continue?")

Sheets("Index").Range("H1").Value = 0
Sheets("Index").Range("I1").Value = 0

If (response = 1) Then
Start = Timer ' Set start time.

Sheets("Scorecard Data").Visible = True
Sheets("Scorecard Data").Select
Columns("GE:GG").Select
Selection.ClearContents
Sheets("Scorecard Data").Visible = True

Sheets("Scorecard Targets").Visible = True
Sheets("Scorecard Targets").Select
Columns("GE:GG").Select
Selection.ClearContents
Sheets("Scorecard Data").Visible = True


For Each f1 In fc
If (f1 < ActiveWorkbook.Path & "\" & ActiveWorkbook.Name) Then
Sheets("Index").Range("I1").Value =
Sheets("Index").Range("I1").Value + 1
End If
Next
For Each f1 In fc
If (f1 < ActiveWorkbook.Path & "\" & ActiveWorkbook.Name) Then
Sheets("Index").Range("H1").Value =
Sheets("Index").Range("H1").Value + 1

filename = f1.Name

Sheets("Scorecard Data").Range("GE" & row_num).Value = "='" & _
folder & "[" & filename & "]Scorecard'!A1"
Sheets("Scorecard Targets").Range("GE" & row_num).Value = "='" & _
folder & "[" & filename & "]Scorecard'!A2"
Sheets("Scorecard Target To Date").Range("GE" & row_num).Value =
"='" & _
folder & "[" & filename & "]Scorecard'!B2"
Sheets("Scorecard Data").Range("GG" & row_num).Value = folder &
filename

row_num = row_num + 1

End If
Next

row_num = 3

Finish = Timer ' Set end time.
TotalTime = Finish - Start ' Calculate total time.

MsgBox "" & Sheets("Index").Range("I1").Value & " Scorecards Gathered in "
&
Round(TotalTime) & " seconds.", vbOKOnly, "Completed"

Sheets("Index").Range("E1").Value = Now

End If

End Sub



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Script for Retrieving Data

hi chinny

See
http://www.rondebruin.nl/fso.htm


--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"chinny" wrote in message ...
Afternoon Guys,

I'm trying to create a script that would allow me to retrieve data of
multiplies excel in any folder.

example. in folder A (c:\folder A\), there is 2 folder (B and D), each of
these folders have 5 excel spreadsheet in them. i want a script that will
collect information of all spreadsheet located in all folders under folder A.
The cell that the information is received from is cell,A1 on sheet
'Scorecard'. The current scrip that i have allows me to gather all
spreadsheet located in 1 folder, not several folders.

The script below is the one currently in use but is only limited to one
folder (A). I want to modify it so that it includes all the folder (B & D) in
that one folder (A) directory.

Sub get_data()

Dim fs, f, f1, fc
Dim row_num As Integer
Dim folder As String
Dim response As Integer
Dim Start As Single, Finish As Single, TotalTime As Single
Dim filename As String

folder = ActiveWorkbook.Path & "\"
row_num = 3

Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFolder(folder)
Set fc = f.Files
response = MsgBox("Collecting scorecards data may take some time. Please be
patient", vbOKCancel, "Continue?")

Sheets("Index").Range("H1").Value = 0
Sheets("Index").Range("I1").Value = 0

If (response = 1) Then
Start = Timer ' Set start time.

Sheets("Scorecard Data").Visible = True
Sheets("Scorecard Data").Select
Columns("GE:GG").Select
Selection.ClearContents
Sheets("Scorecard Data").Visible = True

Sheets("Scorecard Targets").Visible = True
Sheets("Scorecard Targets").Select
Columns("GE:GG").Select
Selection.ClearContents
Sheets("Scorecard Data").Visible = True


For Each f1 In fc
If (f1 < ActiveWorkbook.Path & "\" & ActiveWorkbook.Name) Then
Sheets("Index").Range("I1").Value =
Sheets("Index").Range("I1").Value + 1
End If
Next
For Each f1 In fc
If (f1 < ActiveWorkbook.Path & "\" & ActiveWorkbook.Name) Then
Sheets("Index").Range("H1").Value =
Sheets("Index").Range("H1").Value + 1

filename = f1.Name

Sheets("Scorecard Data").Range("GE" & row_num).Value = "='" & _
folder & "[" & filename & "]Scorecard'!A1"
Sheets("Scorecard Targets").Range("GE" & row_num).Value = "='" & _
folder & "[" & filename & "]Scorecard'!A2"
Sheets("Scorecard Target To Date").Range("GE" & row_num).Value =
"='" & _
folder & "[" & filename & "]Scorecard'!B2"
Sheets("Scorecard Data").Range("GG" & row_num).Value = folder &
filename

row_num = row_num + 1

End If
Next

row_num = 3

Finish = Timer ' Set end time.
TotalTime = Finish - Start ' Calculate total time.

MsgBox "" & Sheets("Index").Range("I1").Value & " Scorecards Gathered in " &
Round(TotalTime) & " seconds.", vbOKOnly, "Completed"

Sheets("Index").Range("E1").Value = Now

End If

End Sub

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
retrieving current data dave303159 Excel Worksheet Functions 1 March 18th 10 07:40 PM
retrieving data Jess Excel Worksheet Functions 1 February 13th 07 04:54 PM
Retrieving data from the web - help ! glynny Excel Worksheet Functions 0 February 20th 06 02:04 AM
Retrieving Web Data leafsfan1967[_6_] Excel Programming 6 June 25th 05 06:47 PM
Retrieving data Alan M[_2_] Excel Programming 5 March 24th 05 12:27 PM


All times are GMT +1. The time now is 07:25 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"