View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.misc
Chip Pearson Chip Pearson is offline
external usenet poster
 
Posts: 7,247
Default Extract workbook information

Try some code like the following:


Sub AAA()
Dim Dest As Range
Dim FName As String
Dim Path As String
Dim WB As Workbook
Dim WS As Worksheet

Set Dest = ThisWorkbook.Worksheets("Sheet1").Range("A1") '<<<
CHANGE
Path = "D:\Temp" '<<< CHANGE
ChDrive Path
ChDir Path
FName = Dir("*.xls")
Do Until FName = vbNullString
Set WB = Workbooks.Open(Filename:=FName)
Set WS = WB.Worksheets("P&L")
Dest(1, 1).Value = WB.Name
Dest(1, 2).Value = WS.Range("C10")
Dest(1, 3).Value = WS.Range("G10")
Set Dest = Dest(2, 1)
WB.Close savechanges:=False
FName = Dir()
Loop
End Sub

Change the lines marked with '<<< to meet your needs. Dest is the cell
at which the list of extracted values will begin. Path is the folder
name that conatins the workbooks whose contents you want to extract.

Cordially,
Chip Pearson
Microsoft Most Valuable Professional,
Excel, 1998 - 2010
Pearson Software Consulting, LLC
www.cpearson.com




On Thu, 20 May 2010 06:59:02 -0700, Joe
wrote:

I want to programmically extract certain information from all workbooks in a
folder, always in the same place on the same sheet in each workbook.

The result will look like this:

Bookname Sales Profit
Book1 999 999
Book2 999 999
etc.

assuming Sales and Profit are in cells c10 and g10 of the sheet named "P&L".