MrExcel Message Board

Go Back   MrExcel Message Board > Question Forums > Excel Questions

Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only.

Reply
 
Thread Tools Display Modes
Old Apr 16th, 2002, 06:49 PM   #1
kevinc
New Member
 
Join Date: Apr 2002
Posts: 1
Default

I use EXCEL 97. I have approxiamately 50 files on my desk top. I would like to transfer sheet 1 on all 50 files to a new workbook, 50 sheets deep. Is this possible with out openeing each file individually and Move/Copy Sheet to new book individually?

Thanks in advance for any help you can provide.
kevinc is offline   Reply With Quote
Old Apr 16th, 2002, 07:18 PM   #2
brettvba
MrExcel MVP
 
Join Date: Feb 2002
Location: Christchurch New Zealand
Posts: 1,030
Default

you would probably have to write some code to do this probably the easist would be to open the workbook then record a macro doing the proceedure you want then just run the macro on each workbook

or you could get excel to open up each workbook but that would take just as long to write the code depending on the workbook names..
brettvba is offline   Reply With Quote
Old Apr 16th, 2002, 07:19 PM   #3
Tom Schreiner
Board Regular
 
Join Date: Mar 2002
Location: Cincinnati, Ohio, USA
Posts: 6,824
Default

Hi
I would place all of the xls files which contain the sheets to be transfered in a new folder. Create a new workbook in this same folder. Paste this code into a standard module, in the new workbook, and run it.
If any of the workbooks in this folder do not have a "Sheet1" then an error will be generated.

Sub CallingAllSheets()
Dim FS, i
Dim PlaceRow As Long
Dim OpenedName As String
Dim DoNotReopenActiveWB_Name As String
Dim RecievingWb As String

Application.DisplayAlerts = False
Application.EnableEvents = False
Application.ScreenUpdating = False
DoNotReopenActiveWB_Name = ActiveWorkbook.Path & "" & ActiveWorkbook.Name
RecievingWb = ActiveWorkbook.Name
PlaceRow = 1
Set FS = Application.FileSearch
With FS
.LookIn = ActiveWorkbook.Path
.Filename = "*.xls"
If .Execute Then
For i = 1 To .FoundFiles.Count
If .FoundFiles(i) <> DoNotReopenActiveWB_Name Then
Workbooks.Open .FoundFiles(i)
OpenedName = ActiveWorkbook.Name
Workbooks(OpenedName).Sheets("Sheet1"). _
Copy Before:=Workbooks(RecievingWb).Sheets(1)
Workbooks(OpenedName).Close savechanges:=False
End If
Next i
End If
End With
Application.DisplayAlerts = True
Application.EnableEvents = True
Application.ScreenUpdating = True
End Sub


Tom
Tom Schreiner is offline   Reply With Quote
Old Apr 16th, 2002, 07:21 PM   #4
BabyTiger
Board Regular
 
Join Date: Mar 2002
Location: Wellington
Posts: 104
Default

Hi,

You may want to try the following:

Sub CopySheets()
Const DeskTopDir = "c:winntprofilesall usersdesktop"
Dim iFileName As String
Dim iWorkBook As String
iWorkBook = ThisWorkbook.Name
iFileName = Dir(DeskTopDir)
Do While iFileName <> ""
If LCase(Right(iFileName, 4)) = ".xls" Then
Workbooks.Open (DeskTopDir & iFileName)
Sheets("sheet1").Name = Left(iFileName, Len(iFileName) - 4)
Sheets(Left(iFileName, Len(iFileName) - 4)).Copy _
After:=Workbooks(iWorkBook).Sheets(Workbooks(iWorkBook).Sheets.Count)
Workbooks(iFileName).Close (False)
End If
iFileName = Dir
Loop
End Sub

For the desktop directory, you might have to change it to whatever desktop directory on yours, eg. windows 98 would be something like : c:windowsdesktop, etc.

And if the name of the sheet you wanted to copy is not called "sheet1", then you also have to change that. Alternatively, if you want to copy the first of the workbook, instead of using 'sheets("sheet1")', change it to 'sheets(1)'.

HTH
BabyTiger is offline   Reply With Quote
Old Apr 17th, 2002, 05:04 AM   #5
swaink
Board Regular
 
Join Date: Feb 2002
Location: South UK
Posts: 344
Default

HI Tom

I've read this with interest because I have a similar requirement, however when I step through the code if the original workbook is found it still try's to open it.

Any Ideas

Kev
swaink is offline   Reply With Quote
Old Apr 18th, 2002, 12:19 PM   #6
Dsuperc
Board Regular
 
Join Date: Apr 2002
Posts: 134
Default

I have a similar problem.The only difference is the files are on the internet.
Dsuperc is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

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 On

Forum Jump


All times are GMT -4. The time now is 01:30 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
All contents Copyright 1998-2012 by MrExcel Consulting.
diabetic desserts recipes recipes Diabetic Soups Holiday Pizza Recipes Popcorn Recipes Recipes For Microwave Pasta Recipes Casserole Recipes Chili Recipes Curry Recipes Crockpot Recipes Apples Recipes Bread Recipes Vegetarian Recipes Vegetable recipes Desserts Recipes Appetizers Ethnic Recipes Meat Dishes Barbecue Recipes Sauces Recipes Marinade Recipes Low Fat Recipes Frugal Gourmet Kitchen Classics Recipes On The Grill Cook Books Seafood Recipes Cajun Recipes Breads Low Fat Low Fat Breads Bread Machine Recipes Yeast Breads Quick Breads Fat Free Vegetarian Salad Recipes Eggplant Recipes Radish Recipes Tomato Recipes Jalapeno Recipes Potato Recipes Lettuce Recipes Cabbage Recipes Beans Ambrosia Recipes Biscotti Recipes Desserts Low Fat Cookie Recipes Cheesecake Recipes Cake Recipes Pie Recipes Muffin Recipes Custard Recipes Best Appetizers Appetizers Low Fat Salsa Recipes Dip Recipes International Recipes Afghan Recipes Alaska Recipes French Recipes German Recipes Greek Recipes Italian Recipes Spanish Recipes Thai Recipes Korean Recipes Chinese Recipes Mexican Recipes Indian Recipes Beef Recipes Pork Pork & Ham Pork Butts Pork Chop Recipes Pork Ribs Rulled Pork Poultry Recipes Stews Recipes Ground Beef Barbecue Grill Barbecue Smoker All Purpose Sauce BBQ Sauce Barbecue Sauce Carolina BBQ Sauce Pickle Recipes Marinades Smoking Low Fat Appetizers & Dips Low Fat Breakfast Low Fat Cakes Low Fat Cheesecakes Low Fat Cookies Low Fat Desserts Low Fat Fish & Seafood Low Fat Meats Low Fat Pasta Low Fat Pies Low Fat Salads Low Fat Sandwiches Low Fat Sauces & Condiments Low Fat Sides Low Fat Soups Low Fat Vegetarian Baker's Dozen Taste of Home Recipe Book Bon Appetit Cookbook Blacktie Cookbook Buster Cook Book Cookbook USA Cook Book Cook Book Sara's Cookbook Sara's Cookbook Appetizers and Dips Poultry recipes Diabetic recipes Holiday recipes Miscellaneous recipes 110 recipes 1986 Usenet cookbook 2900 recipes Cyberrealm recipes Great sysops of world Specialty recipes Ceideburg recipes Cheese recipes Chili recipes Fruits recipes Garlic recipes Great chefs of NY Londontowne recipes Raisins recipes Recipes for kids US Food Vegetarian recipes Bread recipes Drinks Meat Dishes Brisket recipes Caribou recipes Chicken recipes Filet mignons recipes Pork recipes Swordfish recipes Turkey recipes Pasta recipes Uncategorized recipes Ethnic recipes Canada recipes English recipes Ethiopia recipes Germany recipes Greece recipes Mexican recipes Philippines recipes Welsh recipes Microwave recipes Soups recipes Vegetable recipes Asparagus recipes Barley recipes Brown rice recipes Lentil recipes Mushrooms recipes Salads recipes Wild rice Desserts recipes Cakes recipes Chocolate recipes Cookies recipes Ice cream recipes