Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Copy worksheet from multiple files in one DIR to another DIR & rename
Can anyone share idea(s) for code that will programatically loop
through all the .xls files in a directory and copy the second sheet all the .xls files in the "C:\My Documents\Data\month01" directory to a workbook named "tot01.xls" [path is "C:\My Documents\Data\Consol\tot01.xls"] and then name each sheet copied using the value in cell C2 of each of the sheets after it is copied? Any ideas are greatly appreciated. |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Copy worksheet from multiple files in one DIR to another DIR & rename
Sub copysheets()
Dim wkbk As Workbook Dim wkbk1 As Workbook Dim sName As String Dim i As Long On Error Resume Next Set wkbk = Workbooks("tot01.xls") On Error GoTo 0 If wkbk Is Nothing Then Set wkbk = Workbooks.Open( _ "C:\My Documents\Data\Consol\tot01.xls") End If With Application.FileSearch .NewSearch .LookIn = "C:\My Documents\Data\month01" .SearchSubFolders = True .FileName = ".xls" .MatchTextExactly = True .FileType = msoFileTypeExcelWorkbooks If .Execute() 0 Then For i = 1 To .FoundFiles.Count Set wkbk1 = Workbooks.Open( _ .FoundFiles(i)) sName = wkbk1.Worksheets(2). _ Range("C2").Value wkbk1.Worksheets(2).Copy _ After:=wkbk.Worksheets( _ wkbk.Worksheets.Count) wkbk.Worksheets(wkbk.Worksheets. _ Count).Name = sName wkbk1.Close SaveChanges:=False Next i wkbk.Save Else MsgBox "There were no files found." End If End With End Sub -- Regards, Tom Ogilvy Mike Taylor wrote in message m... Can anyone share idea(s) for code that will programatically loop through all the .xls files in a directory and copy the second sheet all the .xls files in the "C:\My Documents\Data\month01" directory to a workbook named "tot01.xls" [path is "C:\My Documents\Data\Consol\tot01.xls"] and then name each sheet copied using the value in cell C2 of each of the sheets after it is copied? Any ideas are greatly appreciated. |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Macro: Copy a worksheet and rename it to a specified value | Excel Discussion (Misc queries) | |||
Copy worksheet and rename sheet | Excel Discussion (Misc queries) | |||
Rename multiple csv files eliminating (-) hyphens from the label. | Excel Discussion (Misc queries) | |||
How to create a copy of a folder having five files in it, & rename | Excel Worksheet Functions | |||
How do I edit a worksheet and copy to multiple files? | Excel Discussion (Misc queries) |