P
Pman
Hi,
I currently have a folder which contains close to 800+ excel files. I need
to copy a range of cells from each of these files to another excel file. I'm
writing a Macro to do this, however It's not working.
I was wondering if someone could go through my code and let me know where I
made a mistake.
Thanks,
Prash
***************************************************
The Code
***************************************************
Sub Macro1()
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set Folder = oFSO.GetFolder("C:\OCFs")
Workbooks.Open Filename:="C:\OCF Destination\Book1.xls"
For Each file In Folder.Files
If file.Type Like "*Excel*" Then
Workbooks.Open Filename:=file.Path
' Unmerging and copying
'
Columns("D").Select
Selection.UnMerge
Range("D7").Select
ActiveWindow.SmallScroll Down:=-6
Range("D1").Select
ActiveCell.FormulaR1C1 = "=CELL(""filename"")"
Range("D1").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Range("D1").Select
ActiveWindow.SmallScroll Down:=42
Range("D166").Select
Selection.Copy
Workbooks.Open Filename:="C:\OCF Destination\Book1.xls"
Range("A65536").End(xlUp).Offset(1, 0).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=True
ActiveWorkbook.Close SaveChanges:=True
End If
Next file
Set oFSO = Nothing
End Sub
***************************************************
I currently have a folder which contains close to 800+ excel files. I need
to copy a range of cells from each of these files to another excel file. I'm
writing a Macro to do this, however It's not working.
I was wondering if someone could go through my code and let me know where I
made a mistake.
Thanks,
Prash
***************************************************
The Code
***************************************************
Sub Macro1()
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set Folder = oFSO.GetFolder("C:\OCFs")
Workbooks.Open Filename:="C:\OCF Destination\Book1.xls"
For Each file In Folder.Files
If file.Type Like "*Excel*" Then
Workbooks.Open Filename:=file.Path
' Unmerging and copying
'
Columns("D").Select
Selection.UnMerge
Range("D7").Select
ActiveWindow.SmallScroll Down:=-6
Range("D1").Select
ActiveCell.FormulaR1C1 = "=CELL(""filename"")"
Range("D1").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Range("D1").Select
ActiveWindow.SmallScroll Down:=42
Range("D166").Select
Selection.Copy
Workbooks.Open Filename:="C:\OCF Destination\Book1.xls"
Range("A65536").End(xlUp).Offset(1, 0).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=True
ActiveWorkbook.Close SaveChanges:=True
End If
Next file
Set oFSO = Nothing
End Sub
***************************************************