Question Merge Excel Files

diven

New member
Joined
Jun 22, 2011
Messages
3
Programming Experience
Beginner
i have 4 different excel files of different names.
each excel file has 8 columns and 15 sheets.
All excel files has same columns and same number of sheets (same sheet names and column names)...
i have to merge these 4 files into one.
that file must be identical to the individual files.i.e same column names,and same number of sheets.
please do help me with that please.am a begginer in programming.
thanks in advance.
hope i can get the solution here...:)
 
You don't even need to do this through VB.NET you could just create a macro to do this and use VBA. However, if you wish you to use VB.NET you will want to create a project with a reference to excel and the excel objects work like so:

Excel Application - This is the highest level object use this to Open Workbooks, etc.
Excel Workbook - This is the excel file, a workbook can have multiple sheets
Excel Worksheet - Columns and Rows (Ranges)

Using those three objects you should be able to loop through the data to copy what you need. If you have any more questions let us know.
 
Dim xl as new Excel.Application
Dim xlBook as Excel.Workbook = xl.Workbooks.Open("Yourexcelfile.xls")
Dim xlSheet as Excel.Worksheet = xlBook.Worksheets("Sheet1")
For x as integer = 1 to 65536
    Dim col1 as string = xlSheet.Cells(x, 1).Value
    Console.Writeline(col1)
Next x


This code will open an excel application, load an excel file, select the sheet named "sheet1" in that file and then output each value in the first column to the console.
 
Dim xl as new Excel.Application
Dim xlBook as Excel.Workbook = xl.Workbooks.Open("Yourexcelfile.xls")
Dim xlSheet as Excel.Worksheet = xlBook.Worksheets("Sheet1")
For x as integer = 1 to 65536
Dim col1 as string = xlSheet.Cells(x, 1).Value
Console.Writeline(col1)
Next x


This code will open an excel application, load an excel file, select the sheet named "sheet1" in that file and then output each value in the first column to the console.

thanks.little by little am understanding what to do..:)
if i have some problems i'll let you know if you don't mind.:p
thanks for your replies..:)
 
Back
Top