Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
jbhoop
 
Posts: n/a
Default combine multiple excel file in to one excel file and multiple worksheet

I am wanting to use the following code to combine worksheets from
multiple files. However I would like to be able to select folder which

contains files in a more automated way that having to change the code
every time, and also copy all worksheets with links and formulas
removed. Any help on this is greatly appreciated as I have limited
code knowledge.


Sub Copy_them()

Dim TargetWkbk As Workbook
Dim mrgWkbk As Workbook



Dim i As Long
Dim Wks As Worksheet
Dim fName As String



Application.ScreenUpdating = False
Set TargetWkbk = Workbooks.Add(1)
ActiveSheet.Name = "dummy"



With Application.FileSearch
.NewSearch
.LookIn = "c:\Temp" 'folder to use
.SearchSubFolders = False
.Filename = "*.xls"
.FileType = msoFileTypeExcelWorkbooks
If .Execute() 0 Then
' MsgBox "There were " & .FoundFiles.Count & " file(s) found."
For i = 1 To .FoundFiles.Count
Set mrgWkbk = Workbooks.Open(.FoundFiles(i))
For Each Wks In ActiveWorkbook.Worksheets
With TargetWkbk
Wks.Copy after:=.Worksheets(.Worksheets.Count)
End With
Next Wks
mrgWkbk.Close False
Next i



Application.DisplayAlerts = False
TargetWkbk.Worksheets("dummy").Delete
Application.DisplayAlerts = True



fName = Application.GetSaveAsFilename _
(fileFilter:="MS Excel Workbook (*.Xls), *.Xls")



TargetWkbk.SaveAs Filename:=fName, FileFormat:=xlNormal, _
Password:="", WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False
Else
MsgBox "There were no files found."
TargetWkbk.Close savechanges:=False
End If
End With



Application.ScreenUpdating = True
Application.EnableEvents = False



End Sub


  #2   Report Post  
Posted to microsoft.public.excel.misc
NUMBnut
 
Posts: n/a
Default combine multiple excel file in to one excel file and multiple work

You may do a paste special, which will allow you paste only the information
you want. Choose paste values if all you want is the text to be pasted.

"jbhoop" wrote:

I am wanting to use the following code to combine worksheets from
multiple files. However I would like to be able to select folder which

contains files in a more automated way that having to change the code
every time, and also copy all worksheets with links and formulas
removed. Any help on this is greatly appreciated as I have limited
code knowledge.


Sub Copy_them()

Dim TargetWkbk As Workbook
Dim mrgWkbk As Workbook



Dim i As Long
Dim Wks As Worksheet
Dim fName As String



Application.ScreenUpdating = False
Set TargetWkbk = Workbooks.Add(1)
ActiveSheet.Name = "dummy"



With Application.FileSearch
.NewSearch
.LookIn = "c:\Temp" 'folder to use
.SearchSubFolders = False
.Filename = "*.xls"
.FileType = msoFileTypeExcelWorkbooks
If .Execute() 0 Then
' MsgBox "There were " & .FoundFiles.Count & " file(s) found."
For i = 1 To .FoundFiles.Count
Set mrgWkbk = Workbooks.Open(.FoundFiles(i))
For Each Wks In ActiveWorkbook.Worksheets
With TargetWkbk
Wks.Copy after:=.Worksheets(.Worksheets.Count)
End With
Next Wks
mrgWkbk.Close False
Next i



Application.DisplayAlerts = False
TargetWkbk.Worksheets("dummy").Delete
Application.DisplayAlerts = True



fName = Application.GetSaveAsFilename _
(fileFilter:="MS Excel Workbook (*.Xls), *.Xls")



TargetWkbk.SaveAs Filename:=fName, FileFormat:=xlNormal, _
Password:="", WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False
Else
MsgBox "There were no files found."
TargetWkbk.Close savechanges:=False
End If
End With



Application.ScreenUpdating = True
Application.EnableEvents = False



End Sub



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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
combine multiple excel file in to one excel file and multiple worksheet jbhoop Excel Discussion (Misc queries) 0 December 29th 05 04:59 PM
Can I embed or link multiple .pdf files into or to an excel file? GrubbyG Excel Discussion (Misc queries) 1 October 3rd 05 08:40 PM
why does excel create multiple copies (as many as 18) of a file? Beezie Excel Discussion (Misc queries) 6 August 11th 05 03:55 PM
Multiple people accessing an Excel file from a server at once. UABCSA Excel Discussion (Misc queries) 1 May 2nd 05 05:41 PM
Multiple excel users can open the same file and edit at the same . Jeff Howard Excel Discussion (Misc queries) 1 February 18th 05 12:19 PM


All times are GMT +1. The time now is 02:33 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"