Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 921
Default Copying sheets form other workbooks

Good morning all,
I have 5 to 8 workbooks in a folder called Class. The workbooks will not
always have the same name but they will only contain one sheet in each book.
I would like to copy that sheet from each workbook into the current workbook.
Is there a way to copy all sheets from all workbooks from a folder such as
c:\class.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Copying sheets form other workbooks

Hi Jeff,

See Ron de Bruin's sample code at:

http://www.rondebruin.nl/copy3.htm#sheet

See particularly Sub Example11 on that page.

---
Regards,
Norman



"Jeff" wrote in message
...
Good morning all,
I have 5 to 8 workbooks in a folder called Class. The workbooks will not
always have the same name but they will only contain one sheet in each
book.
I would like to copy that sheet from each workbook into the current
workbook.
Is there a way to copy all sheets from all workbooks from a folder such as
c:\class.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 921
Default Copying sheets form other workbooks

That is what I was looking for. Thank you very much Norman!

"Norman Jones" wrote:

Hi Jeff,

See Ron de Bruin's sample code at:

http://www.rondebruin.nl/copy3.htm#sheet

See particularly Sub Example11 on that page.

---
Regards,
Norman



"Jeff" wrote in message
...
Good morning all,
I have 5 to 8 workbooks in a folder called Class. The workbooks will not
always have the same name but they will only contain one sheet in each
book.
I would like to copy that sheet from each workbook into the current
workbook.
Is there a way to copy all sheets from all workbooks from a folder such as
c:\class.




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Copying sheets form other workbooks

Hi Jeff,

How about something like this ...

In a standard module of the master workbook where you want worksheets copied
into, paste the following code.

Sub CopySheets()
Dim fd As FileDialog
Dim vrtSelectedItem As Variant
Dim wsName As String

' Create a FileDialog object as a Folder Picker dialog box.
' Allows user to select the folder at run-time.
' (Or just hardcode the value of wsName below).
Set fd = Application.FileDialog(msoFileDialogFolderPicker)

With fd
' Use the Show method to display the Folder Picker
' dialog box and return the user's action.
If .Show = -1 Then ' The user pressed the OK button.
vrtSelectedItem = .SelectedItems(1)
' Folder Picker does not allow multi-select so must be 1.
Else ' The user pressed Cancel.
Exit Sub
End If
End With

' Assuming all files that you're looking for
' are Excel workbooks with a .xls extension ...
wsName = Dir(vrtSelectedItem & Application.PathSeparator & "*.xls")
Application.ScreenUpdating = False ' Prevent screen flickering
Do While Len(wsName) 0
Workbooks.Open Filename:=wsName, ReadOnly:=True
With ActiveWorkbook
.Sheets(1).Copy
After:=ThisWorkbook.Sheets(ThisWorkbook.Sheets.Cou nt)
.Close SaveChanges:=False
End With
wsName = Dir ' Get the next workbook (if there is one)
Loop
Application.ScreenUpdating = True

'Set the object variable to Nothing.
Set fd = Nothing
End Sub


Note: This routine will copy the first worksheet of every *.xls workbook in
the selected folder into the workbook from which this code is run. In order
to avoid duplication, you may want to move *.xls files out of the selected
folder after they have been successfully processed into your master
workbook.

Trust this helps and let me know how you get on.

Enjoy! Sean.

"Jeff" wrote in message
...
Good morning all,
I have 5 to 8 workbooks in a folder called Class. The workbooks will not
always have the same name but they will only contain one sheet in each
book.
I would like to copy that sheet from each workbook into the current
workbook.
Is there a way to copy all sheets from all workbooks from a folder such as
c:\class.



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 921
Default Copying sheets form other workbooks

That works very well also. Thank you very much!

"Sean T. Connolly" wrote:

Hi Jeff,

How about something like this ...

In a standard module of the master workbook where you want worksheets copied
into, paste the following code.

Sub CopySheets()
Dim fd As FileDialog
Dim vrtSelectedItem As Variant
Dim wsName As String

' Create a FileDialog object as a Folder Picker dialog box.
' Allows user to select the folder at run-time.
' (Or just hardcode the value of wsName below).
Set fd = Application.FileDialog(msoFileDialogFolderPicker)

With fd
' Use the Show method to display the Folder Picker
' dialog box and return the user's action.
If .Show = -1 Then ' The user pressed the OK button.
vrtSelectedItem = .SelectedItems(1)
' Folder Picker does not allow multi-select so must be 1.
Else ' The user pressed Cancel.
Exit Sub
End If
End With

' Assuming all files that you're looking for
' are Excel workbooks with a .xls extension ...
wsName = Dir(vrtSelectedItem & Application.PathSeparator & "*.xls")
Application.ScreenUpdating = False ' Prevent screen flickering
Do While Len(wsName) 0
Workbooks.Open Filename:=wsName, ReadOnly:=True
With ActiveWorkbook
.Sheets(1).Copy
After:=ThisWorkbook.Sheets(ThisWorkbook.Sheets.Cou nt)
.Close SaveChanges:=False
End With
wsName = Dir ' Get the next workbook (if there is one)
Loop
Application.ScreenUpdating = True

'Set the object variable to Nothing.
Set fd = Nothing
End Sub


Note: This routine will copy the first worksheet of every *.xls workbook in
the selected folder into the workbook from which this code is run. In order
to avoid duplication, you may want to move *.xls files out of the selected
folder after they have been successfully processed into your master
workbook.

Trust this helps and let me know how you get on.

Enjoy! Sean.

"Jeff" wrote in message
...
Good morning all,
I have 5 to 8 workbooks in a folder called Class. The workbooks will not
always have the same name but they will only contain one sheet in each
book.
I would like to copy that sheet from each workbook into the current
workbook.
Is there a way to copy all sheets from all workbooks from a folder such as
c:\class.






  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 921
Default Copying sheets form other workbooks

I think it would be a good idea to move or delete the files as I copy them.
How would I do that?

"Sean T. Connolly" wrote:

Hi Jeff,

How about something like this ...

In a standard module of the master workbook where you want worksheets copied
into, paste the following code.

Sub CopySheets()
Dim fd As FileDialog
Dim vrtSelectedItem As Variant
Dim wsName As String

' Create a FileDialog object as a Folder Picker dialog box.
' Allows user to select the folder at run-time.
' (Or just hardcode the value of wsName below).
Set fd = Application.FileDialog(msoFileDialogFolderPicker)

With fd
' Use the Show method to display the Folder Picker
' dialog box and return the user's action.
If .Show = -1 Then ' The user pressed the OK button.
vrtSelectedItem = .SelectedItems(1)
' Folder Picker does not allow multi-select so must be 1.
Else ' The user pressed Cancel.
Exit Sub
End If
End With

' Assuming all files that you're looking for
' are Excel workbooks with a .xls extension ...
wsName = Dir(vrtSelectedItem & Application.PathSeparator & "*.xls")
Application.ScreenUpdating = False ' Prevent screen flickering
Do While Len(wsName) 0
Workbooks.Open Filename:=wsName, ReadOnly:=True
With ActiveWorkbook
.Sheets(1).Copy
After:=ThisWorkbook.Sheets(ThisWorkbook.Sheets.Cou nt)
.Close SaveChanges:=False
End With
wsName = Dir ' Get the next workbook (if there is one)
Loop
Application.ScreenUpdating = True

'Set the object variable to Nothing.
Set fd = Nothing
End Sub


Note: This routine will copy the first worksheet of every *.xls workbook in
the selected folder into the workbook from which this code is run. In order
to avoid duplication, you may want to move *.xls files out of the selected
folder after they have been successfully processed into your master
workbook.

Trust this helps and let me know how you get on.

Enjoy! Sean.

"Jeff" wrote in message
...
Good morning all,
I have 5 to 8 workbooks in a folder called Class. The workbooks will not
always have the same name but they will only contain one sheet in each
book.
I would like to copy that sheet from each workbook into the current
workbook.
Is there a way to copy all sheets from all workbooks from a folder such as
c:\class.




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
Copying Sheets between workbooks without links Air-ron Excel Discussion (Misc queries) 3 February 25th 09 09:03 PM
copying workbooks acomputer4u Excel Worksheet Functions 3 November 25th 06 06:29 PM
Copying Sheets Between Workbooks Jon C[_2_] Excel Programming 2 June 3rd 05 11:40 AM
Copying Sheets to New workbooks Andibevan[_2_] Excel Programming 2 April 29th 05 04:32 PM
Copying from several workbooks into one Anthony Gobel Excel Programming 0 April 6th 04 09:56 PM


All times are GMT +1. The time now is 07:07 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"