You needed it for XLS files... my bad... try the following macro:
Sub OpenFiles()
Dim fn As Variant, f As Integer, i As Integer, counter As Integer
i = 1
fn = Application.GetOpenFilename("Excel Files,*.xls", _
1, "Select One Or More Files To Open",
, True)
If TypeName(fn) = "Boolean" Then Exit Sub
For f = 1 To UBound(fn)
Debug.Print "Selected file #" & f & ": " & fn(f)
Workbooks.Open fn(f)
While i = 1
Range("G25").Select
Selection.Copy
Windows("Work.xls").Activate
Range("A1").Select
ActiveSheet.Paste
i = i + 1
Wend
If (f > 1) Then
While (i <= f)
Range("G25").Select
Selection.Copy
Windows("Work.xls").Activate
Range("A1").Select
Cells(i, 1).Select
ActiveSheet.Paste
i = i + 1
Wend
End If
ActiveWindow.ActivateNext
ActiveWindow.Close False
Next f
End Sub
"Mark Ivey" <(E-Mail Removed)> wrote in message
news:59DF9AA9-AB30-453F-91C5-(E-Mail Removed)...
> Here is one method...
>
> You will need a workbook with the filename "Work.xls" for this one to
> work out right. Also you can only have the "Work.xls" file open when you
> run this macro or it will not work correctly.
>
> With the workbook "Work.xls" open, make a new module and paste the
> following code...
>
> Then run the macro.
>
>
> Sub OpenFiles()
> Dim fn As Variant, f As Integer, i As Integer, counter As Integer
>
> i = 1
> fn = Application.GetOpenFilename("CSV Files,*.csv", _
> 1, "Select One Or More Files To Open",
> , True)
> If TypeName(fn) = "Boolean" Then Exit Sub
> For f = 1 To UBound(fn)
> Debug.Print "Selected file #" & f & ": " & fn(f)
> Workbooks.Open fn(f)
>
> While i = 1
>
> Range("G25").Select
> Selection.Copy
> Windows("Work.xls").Activate
> Range("A1").Select
> ActiveSheet.Paste
>
> i = i + 1
> Wend
>
> If (f > 1) Then
>
> While (i <= f)
> Range("G25").Select
> Selection.Copy
> Windows("Work.xls").Activate
> Range("A1").Select
> Cells(i, 1).Select
> ActiveSheet.Paste
>
> i = i + 1
> Wend
>
> End If
>
> ActiveWindow.ActivateNext
> ActiveWindow.Close False
>
> Next f
> End Sub
>
>
>
>
>
>
>
>
>
>
>
> "Tony" <(E-Mail Removed)> wrote in message
> news:AEF71159-5254-4EC5-B095-(E-Mail Removed)...
>> Hi
>>
>> I have a data in Cells G25. And I have 20 xls files in a folder.
>>
>> What i want to do is I would like to copy the cells G25 from this 20 xls
>> files into a new workbook. How could I do that?
>>
>> Please can i have some help?
>>
>> Thanks a lot
>>
>> Tony
>
|