Exforsys

Online Training

Combining files

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. ...


Go Back   Exforsys > Articles and Tutorials > Visual Basic Tutorials

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

 

LinkBack Thread Tools
  #1 (permalink)  
Old 11-19-2004, 08:51 PM
Junior Member
 
Join Date: Nov 2004
Posts: 8
powerstar
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!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 11-19-2004, 09:18 PM
Senior Member
 
Join Date: Nov 2004
Posts: 177
sanereddy is an unknown quantity at this point
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\&quot
aa = 1
Do While (fName <> \"\&quot
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\&quot
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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 11-19-2004, 10:31 PM
Junior Member
 
Join Date: Nov 2004
Posts: 8
powerstar
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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 11-19-2004, 10:34 PM
Junior Member
 
Join Date: Nov 2004
Posts: 8
powerstar
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?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 11-19-2004, 11:37 PM
Senior Member
 
Join Date: Nov 2004
Posts: 177
sanereddy is an unknown quantity at this point
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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 11-19-2004, 11:51 PM
Junior Member
 
Join Date: Nov 2004
Posts: 8
powerstar
Re:Combining files

I have used only shcopy() procedure but still it is not working.
Please help me.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 11-20-2004, 12:03 AM
Senior Member
 
Join Date: Nov 2004
Posts: 177
sanereddy is an unknown quantity at this point
Re:Combining files

donwload this and rename to .xls file. tested it, works. [file name=Merge.xls.txt size=24064]http://www.exforsys.com/components/com_simpleboard/uploaded/files/Merge.xls.txt[/file]
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 11-20-2004, 12:04 AM
Junior Member
 
Join Date: Nov 2004
Posts: 8
powerstar
Re:Combining files

What I want to do is not a one time process.
it needs to be done every month end.and it is done by end users who doesnt want to install anything on their machines.

Thank you so much for your help.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 11-20-2004, 12:09 AM
Senior Member
 
Join Date: Nov 2004
Posts: 177
sanereddy is an unknown quantity at this point
Re:Combining files

use this excel file for testing , there is no need to install any.

for logterm to do this on monthly basic, then basically we need to do this visual basic and compile as executable.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 11-20-2004, 12:11 AM
Junior Member
 
Join Date: Nov 2004
Posts: 8
powerstar
Re:Combining files

I worked partially.
It copied ONLY one file and giving this error :400.

I really appreciate your help.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads

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


All times are GMT -4. The time now is 07:08 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0
Copyright 2004 - 2007 Exforsys Inc. All rights reserved.