extracting data many worksheets
RH

Forum home » Delegate support and help forum » Microsoft Excel VBA Training and help » Extracting Data from many worksheets

Extracting Data from many worksheets

resolvedResolved · Medium Priority · Version 2003

Rory has attended:
Excel VBA Intro Intermediate course

Extracting Data from many worksheets

How do you code VBA so that within a particular folder (say C:mydocuments/Excel), open every document in turn and perform the same task on each document. For example if data need to be extracted from many returned forms and all such forms are saved in the same location.

RE: Extracting Data from many worksheets

Thank you for your question.

The command you need is Dir which returns filenames. The first time you use it you specify the location and mask and then you just use dir to find the next match. When dir finds no more files it returns an empty string.

Example

Sub ReportFiles()

Dim FoundFile As String
'Find first file
FoundFile = Dir("c:\reports\*.xls")
Do While FoundFile > ""
Workbooks.Open FileName:="c:\reports\" & FoundFile
' Process each file
'
' Get name of next file
FileName = Dir
Loop

End Sub




Please let me know how you get on.


Laura GB

 

Training courses

 

Training information:

Welcome. Please choose your application (eg. Excel) and then post your question.

Our Microsoft Qualified trainers will then respond within 24 hours (working days).

Frequently Asked Questions
What does 'Resolved' mean?

Any suggestions, questions or comments? Please post in the Improve the forum thread.


 

Excel tip:

Change Excel's default font

You can change the default font and font size for all spreadsheets created in Excel by:

1. Going to Tools on the menu bar.
2. Select Options, then General.
3. Next to Standard Font you can change the font and font size.
4. Click OK.

Each new file you start from this point onward should use the font and font size you have selected.

View all Excel hints and tips


Server loaded in 0.05 secs.