Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Macro Compiles Sheets to One Book...Small Modification Needed


I have been using the following macro to collect all of the first sheet
stored in multiple workbooks. Now, I am trying to change this macro s
that it will collect all of the sheets in each of the workbooks and no
just the first sheet in each book. Any ideas?


Code
-------------------
Sub GetFiles()
Dim basebook As Workbook
Dim mybook As Workbook
Dim sourceRange As Range
Dim destrange As Range
Dim FNames As String
Dim MyPath As String
Dim SaveDriveDir As String

SaveDriveDir = CurDir
MyPath = "C:\Documents and Settings\desktop\testfolder"
ChDrive MyPath
ChDir MyPath
FNames = Dir("*.xls")
If Len(FNames) = 0 Then
MsgBox "No files in the Directory"
ChDrive SaveDriveDir
ChDir SaveDriveDir
Exit Sub
End If

Application.ScreenUpdating = False
Set basebook = ThisWorkbook
Do While FNames < ""
Set mybook = Workbooks.Open(FNames)
mybook.Worksheets(1).Copy after:= _
basebook.Sheets(basebook.Sheets.Count)
On Error Resume Next
ActiveSheet.Name = Left(mybook.Name, Len(mybook.Name) - 4)
On Error GoTo 0

' You can use this if you want to copy only the values
' With ActiveSheet.UsedRange
' .Value = .Value
' End With

mybook.Close False
FNames = Dir()
Loop
ChDrive SaveDriveDir
ChDir SaveDriveDir
Application.ScreenUpdating = True

Application.DisplayAlerts = False
Sheets("Sheet1").Select
ActiveWindow.SelectedSheets.Delete
Application.DisplayAlerts = False




End Su
-------------------

--
TEA
-----------------------------------------------------------------------
TEAM's Profile: http://www.excelforum.com/member.php...fo&userid=2281
View this thread: http://www.excelforum.com/showthread.php?threadid=46791

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Macro Compiles Sheets to One Book...Small Modification Needed

Hi Team

mybook.Worksheets.Copy after:= _

You can use this but what do you want to do with the sheet names ?

On Error Resume Next
ActiveSheet.Name = Left(mybook.Name, Len(mybook.Name) - 4)
On Error GoTo 0



--
Regards Ron de Bruin
http://www.rondebruin.nl


"TEAM" wrote in message
...

I have been using the following macro to collect all of the first sheets
stored in multiple workbooks. Now, I am trying to change this macro so
that it will collect all of the sheets in each of the workbooks and not
just the first sheet in each book. Any ideas?


Code:
--------------------
Sub GetFiles()
Dim basebook As Workbook
Dim mybook As Workbook
Dim sourceRange As Range
Dim destrange As Range
Dim FNames As String
Dim MyPath As String
Dim SaveDriveDir As String

SaveDriveDir = CurDir
MyPath = "C:\Documents and Settings\desktop\testfolder"
ChDrive MyPath
ChDir MyPath
FNames = Dir("*.xls")
If Len(FNames) = 0 Then
MsgBox "No files in the Directory"
ChDrive SaveDriveDir
ChDir SaveDriveDir
Exit Sub
End If

Application.ScreenUpdating = False
Set basebook = ThisWorkbook
Do While FNames < ""
Set mybook = Workbooks.Open(FNames)
mybook.Worksheets(1).Copy after:= _
basebook.Sheets(basebook.Sheets.Count)
On Error Resume Next
ActiveSheet.Name = Left(mybook.Name, Len(mybook.Name) - 4)
On Error GoTo 0

' You can use this if you want to copy only the values
' With ActiveSheet.UsedRange
' .Value = .Value
' End With

mybook.Close False
FNames = Dir()
Loop
ChDrive SaveDriveDir
ChDir SaveDriveDir
Application.ScreenUpdating = True

Application.DisplayAlerts = False
Sheets("Sheet1").Select
ActiveWindow.SelectedSheets.Delete
Application.DisplayAlerts = False




End Sub
--------------------


--
TEAM
------------------------------------------------------------------------
TEAM's Profile: http://www.excelforum.com/member.php...o&userid=22810
View this thread: http://www.excelforum.com/showthread...hreadid=467916



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
Losing Macro When Coping Sheets into a New Book Vick Excel Discussion (Misc queries) 3 May 15th 08 10:59 PM
Macro for part of W/book sheets TUNGANA KURMA RAJU Excel Discussion (Misc queries) 2 March 9th 06 05:57 AM
a macro problem with a lot of sheets in a book. cheddar Excel Programming 2 February 18th 04 04:36 PM
Formula Modification Needed Phil Hageman[_3_] Excel Programming 4 December 18th 03 07:19 PM
macro stops copying sheets into a book after the 11th sheet MISMitch Excel Programming 1 October 22nd 03 05:27 PM


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