This is a discussion on Combining files within the Visual Basic Tutorials forums, part of the Articles and Tutorials category; Hi, Can anybody please help me in doing this? I have to combine a number of excel files into one. ...
|
|||||||
| Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
Combining files
Hi,
Can anybody please help me in doing this? I have to combine a number of excel files into one. Number of columns does not change but number of rows change from file to file. The names of the files are different . All the files will be in a folder. Iam running Microsoft Excel 2003. thanks in advance! |
|
|||
|
Re:Combining files
Here it is, might need bit tweaking, I haven\'t tested the code on my pc. it\'s simple vbscript code.
put all the files that has to be merged in c:\\temp directory. open a new workbook hit alt+f11 this opens vbe window select modules form insert menu, paste the code below, close the vbe window. in xl hit alt+f8 select scopy click run Sub shcopy() Dim xlBook As Excel.Workbook Dim tBook As Excel.Workbook Dim xlSht As Excel.Worksheet Set tBook = ThisWorkbook fName = Dir(\"c:\\temp\\*.xls\" ![]() aa = 1 Do While (fName <> \"\" ![]() Set xlBook = Workbooks.Open(\"c:\\temp\\\" & fName) Set xlSht = xlBook.Sheets(1) xlSht.UsedRange.Copy tBook.Activate Cells(aa, 1).Select ActiveSheet.Paste ActiveSheet.UsedRange.Select aa = Selection.Rows.Count + 2 xlBook.Save xlBook.Close fName = Dir Loop Set xlBook = Nothing Set xlSht = Nothing Set tBook = Nothing End Sub if you would like to copy many tabs from into one spreadhseet within one excel file... Sub CombineFilesInFolder() Dim pathname As String Dim filename As String Dim rng As Range dim tmprng as Range Dim thiswrk As Workbook Dim thissht As Worksheet Dim wrk As Workbook Dim sht As Worksheet Set thiswrk = ThisWorkbook Set thissht = thiswrk.Sheets(1) Application.ScreenUpdating = False pathname = \"\\\\Globasrvr\\globafone\\Billing\\OrangeBillingTools\\Orange_Excel_Sheets_From_Dean\\\" filename = Dir(pathname & Application.PathSeparator & \"*.xls\" ![]() Do Until filename = \"\" Set wrk = Workbooks.Open(pathname & Application.PathSeparator & filename) Set sht = wrk.Sheets(1) Set tmprng = sht.UsedRange Set rng = sht.UsedRange rng.Copy thissht.Cells(thissht.UsedRange.Rows.Count + 1, 1) wrk.Close False filename = Dir() Loop Set sht = Nothing Set wrk = Nothing Application.ScreenUpdating = True End Sub Hope this helps. |
|
|||
|
Re:Combining files
Sanereddy,
I copied your code and ran the macro.It didnt work.The sheet remains balnk. iam sorry.I dont know anything about VB so i could not even make minor modifications to your code. Iam a peoplesoft developer and iam generating these excel files using nVision. Could you please check the macro for any modifications to be made? thank you very much. |
|
|||
|
Re:Combining files
I see 2 procedures in your code
1)Sub shcopy() 2)Sub CombineFilesInFolder() But we r running ONLY shcopy() procedure.I dont see any call to the procedure CombineFilesInFolder() from shcopy(). do we need to call it? |
|
|||
|
Re:Combining files
Download tthis excel file, put all the files in c:\\temp folder,
al+f8 to run, there are 2 msgbox commands in the code, you can take them out after testing. discussion board stripped few symbols from the code. hope this helps. vamsee Post edited by: sanereddy, at: 2004/11/19 23:03 |
![]() |
| Thread Tools | |
|
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| comp.sys.hp.hpux FAQ | Ian P. Springer | Tech FAQ | 0 | 10-19-2005 01:39 AM |
| Compaq Contura Aero Frequently Asked Questions | Philip Wilk | Tech FAQ | 0 | 10-19-2005 01:38 AM |
| Apple II Csa2 FAQs: Uploading & Downloading, Part 21/25 | rubywand@swbell.net | Tech FAQ | 0 | 08-08-2004 01:14 AM |
| comp.sys.hp.hpux FAQ | Ian P. Springer | Tech FAQ | 0 | 06-28-2004 03:44 PM |
| Apple II Csa2 FAQs: Uploading & Downloading, Part 21/25 | rubywand@swbell.net | Tech FAQ | 0 | 05-04-2004 10:01 AM |