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 25th, 2002, 08:48 AM   #1
buntykins
Board Regular
 
Join Date: Apr 2002
Posts: 76
Default

I have this folder you see containing about 60 different workbooks. I have this macro that goes into each one and copies certain data and pastes it into a summary workbook. The thing is, I have only just finished doing it for TWO people!! And that's taken me ages to record!!! Is there any way of telling the macro what to do, and commanding it to do it to all the workbooks in the folder as it's the same operation I need over and over again. The code is here:

Workbooks.Open FileName:= _
"bluehbennettCustomer Services DebtJoe Bloggs.xls"
Range("A2").Select
ActiveWindow.SmallScroll Down:=228
Range("A2:J250").Select
Selection.Copy
Windows("Statistics Collation.xls").Activate
Range("A4").Select
ActiveSheet.Paste
Range("A4").Select
Windows("Joe Bloggs.xls").Activate
Application.CutCopyMode = False
ActiveWindow.LargeScroll Down:=-8
Range("A1").Select
Sheets("Sheet1").Select
ActiveWindow.Close

I will be sooooooooo grateful if someone can help as I am completely stumped (as usual!). Thank you, thank you, thank you in advance

Janie
xxxxxxx

[ This Message was edited by: buntykins on 2002-04-25 07:48 ]
buntykins is offline   Reply With Quote
Old Apr 25th, 2002, 09:00 AM   #2
jrnyman
Board Regular
 
Join Date: Mar 2002
Location: Boston, MA
Posts: 105
Default

Do you always paste it to A4?
jrnyman is offline   Reply With Quote
Old Apr 25th, 2002, 09:03 AM   #3
buntykins
Board Regular
 
Join Date: Apr 2002
Posts: 76
Default

No, I actually paste it to the next available row, but I know how to record that "Go to A65536 and then press CTRL Up" thing so I thought I could insert that somewhere. I know I sound really stupid it's just that this is something I have been working on for months now, and it's nearly completed, so I'm getting all flustered and excited about it!

if it's possible I'd like it to paste the first one to A4, then the next one to A254, then the next one to A504, then to A754 and so on, going up in 250's. I don't suppose anyone knows how to do that as well do they?

Janie
xx

[ This Message was edited by: buntykins on 2002-04-25 08:05 ]
buntykins is offline   Reply With Quote
Old Apr 25th, 2002, 09:07 AM   #4
jrnyman
Board Regular
 
Join Date: Mar 2002
Location: Boston, MA
Posts: 105
Default

My manuAl method would be to manually open the workbook, run this code, then open the next workbook, etc. Should only take a few minutes for 60 workbooks. I made the assumption that you are copying the data to the next empty row.

ThisSheet = ActiveWindow.name
Range("A2:J250").Copy
Windows("Statistics Collation.xls").Activate
Range("A65536").End(x1Up).Offset(1,0).Select
ActiveSheet.Paste
Windows(ThisSheet).Activate
ActiveWindow.Close
jrnyman is offline   Reply With Quote
Old Apr 25th, 2002, 09:08 AM   #5
jasonking
New Member
 
Join Date: Apr 2002
Posts: 3
Default

You need to make use of the 'Microsoft Scripting Runtime' reference, if you have not already. (Tools->References...)

You need to use the following:

Dim objFSO As New FileSystemObject
Dim fol As Folder
Dim fls As Files
Dim fil As File

Set fol = objFSO.GetFolder()

Set fls = fol.Files

For Each fil In fls

If (fil.Type = "Microsoft Excel Worksheet") Then


Range("A4").Select
ActiveSheet.Paste
Range("A4").Select
>

End If

Next

Set fil = Nothing
Set fls = Nothing
Set fol = Nothing
Set objFSO = Nothing

Note: You need to specify the folder somehow. You could enter the path in a cell perhaps.

-----
Jason
jasonking is offline   Reply With Quote
Old Apr 25th, 2002, 09:10 AM   #6
AJ
Board Regular
 
Join Date: Mar 2002
Location: =ActiveCell.Address
Posts: 478
Default


Just because I can't resist a post with a subject line like this one(!) try the below. It moves each file to a processed subdirectory after it's finished with the file which is something I've found helpful...

Sub getdata()

Dim MyPath As String
Dim MyFile As String
Dim MyIncrement As Long

'Set start row for pasting.
MyIncrement = 4

'Change the drive to whatever drive you're on
ChDrive "C"


'Define Path - change to whatever..
MyPath = "C:temp"

'Change directory to your directory
ChDir (MyPath)

' See if a subdirectoy called "Processed" exists
MyCheckDir = Dir(MyPath & "Processed", vbDirectory)

'If it doesn't exist then create it
If MyCheckDir = "" Then
MkDir MyPath & "Processed"
End If

' Now go looking for Excel files to process
ChDir MyPath & ""
MyFile = Dir("*.xls", vbNormal)

Do While MyFile <> ""

Workbooks.Open Filename:=MyFile

'Do your stuff here (have shortened the code a bit - there were some unnecessary lines)...

Range("A2:J250").Copy
Windows("Statistics Collation.xls").Activate
Range("A" & MyIncrement).Select
ActiveSheet.Paste
Application.CutCopyMode = False

'Switch back to the open Excel file and close it, without saving
Windows(MyFile).Activate
ActiveWorkbook.Close SaveChanges:=0

'Copy the file we've processed to the Processed Directory
FileCopy MyPath & "" & MyFile, MyPath & "Processed" & MyFile
'Delete original
Kill MyFile

' Call Dir again without arguments to return the next *.XLS file in
' the same directory.
MyFile = Dir

'Increment the value for pasting
MyIncrement = MyIncrement + 250

Loop
End Sub


Rgds
AJ
AJ is offline   Reply With Quote
Old Apr 25th, 2002, 09:15 AM   #7
buntykins
Board Regular
 
Join Date: Apr 2002
Posts: 76
Default

You'll have to forgive me, both of you but I've never seen anything like either of these things before, so I'm not exactly sure how to implement them. Both of them sound intriguing but how do I get the going?

Jrnyman - How do I specify in your code which folder to look in to open all the workbooks?

Jasonking - When you say specify the folder, could I put this in the code somewhere, and if so, where?

Sorry to be so blonde! Thanks heaps to both of you!

Janie
xxxxx
buntykins is offline   Reply With Quote
Old Apr 25th, 2002, 09:17 AM   #8
buntykins
Board Regular
 
Join Date: Apr 2002
Posts: 76
Default

AJ, this sounds perfect, but when you say about the processed subdirectory, where would this be? What would it be called?

Janie
buntykins is offline   Reply With Quote
Old Apr 25th, 2002, 09:21 AM   #9
AJ
Board Regular
 
Join Date: Mar 2002
Location: =ActiveCell.Address
Posts: 478
Default

Hiya,

In the example it would be C:tempprocessed. Basically, it creates a processed directory off of whatever path you put in in the define path bit near the top of the macro so you can change that bit however you want.

Rgds
AJ


(P.S. remember, anywhere you see two backslashes on this board always swap them for just one - the board seems to automagically add a backslash before a lot of characters in postings, one of which characters is a backslash! Hence the doubling up.)
AJ is offline   Reply With Quote
Old Apr 25th, 2002, 09:21 AM   #10
jasonking
New Member
 
Join Date: Apr 2002
Posts: 3
Default

Apologies, my posted message messed up when sending.

Btw, Your code will go within the 'If' statement. (That's one bit that messed up).

You can specify the folder's path in the code by entering:

Set fol = objFSO.GetFolder("c:workbooks")

Or you could enter the path in a cell of the current workbook (say cell 'A1'). Then the code would be:

Set fol = objFSO.GetFolder(Range("A1")

-----
Jason
jasonking 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:19 PM.


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