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 18th, 2002, 05:33 PM   #1
robfo0
Board Regular
 
Join Date: Feb 2002
Location: Stockton, California
Posts: 281
Default

Hi everyone,

OK heres what I'm trying to do:

I have a workbook (wrkbook1) with code that opens another workbook(wrkbook2), and copies one of the sheets to wrkbook1. The sheet i am copying is named "copysheet" and contains a piece of code called "butt*******".

after the sheet is copy, the same running macro tries to call "butt*******". I thought it should work because if the worksheet opens and copies, the code will be there. BUT, the macro stops before it does anything because it cant find the "butt*******" macro! (this is ofcourse because the sheet with the code hasnt been copied yet) I get the error not defined.

Is there a way to make the macro run anyway, then it "SHOULD" work?

Thanks
robfo0 is offline   Reply With Quote
Old Apr 18th, 2002, 05:41 PM   #2
brettvba
MrExcel MVP
 
Join Date: Feb 2002
Location: Christchurch New Zealand
Posts: 1,030
Default

post your code i will have a look.
brettvba is offline   Reply With Quote
Old Apr 18th, 2002, 05:48 PM   #3
robfo0
Board Regular
 
Join Date: Feb 2002
Location: Stockton, California
Posts: 281
Default

in the first workbook, named "wrkbook1" there is this code:

sub opencopy()
currbook=Activeworkbook.name

'Open
Workbooks.Open Filename:= _
"S:wrkbook2.xls", ReadOnly:=True
Sheets("copysheet").Select
Sheets("copysheet").Move Before:=Workbooks(currbook).Worksheets(Worksheets.Count)
Sheets("copysheet").Unprotect

call butt*******
end sub


then the 2nd workbook named: "wrkbook2" contains the sheet being copied, named "copysheet". "copysheet" has the following code in it (code is NOT in a module, but on the sheet):

sub butt*******()
msgbox("code worked")
end sub


so, as you can see, from the first workbooks code, IF the sheet is copied, the butt******* code will be available for execution, but the macro doesnt do ANYTHING because before it even runs, the code errors because it cant find butt******* yet.

Thanks
robfo0 is offline   Reply With Quote
Old Apr 18th, 2002, 07:15 PM   #4
brettvba
MrExcel MVP
 
Join Date: Feb 2002
Location: Christchurch New Zealand
Posts: 1,030
Default

try

Application.Run "Book2.xls!butt*******"

where book2 is where the butt******* macro is sorry i took so long to respond having lunch!!
brettvba is offline   Reply With Quote
Old Apr 18th, 2002, 08:27 PM   #5
robfo0
Board Regular
 
Join Date: Feb 2002
Location: Stockton, California
Posts: 281
Default

brettvba,

that worked, but one part i left out and still have a question about.

the 2nd workbook has ONLY one worksheet (copysheet) and i did this purposely so that when the sheet is moved, it will close automatically.

When i use your code, it opens another copy of the workbook...instead of going through the hassle of adding more code, is there ANY way to refer to the code on the copysheet in wrkbook1 after its copied over? This would save me some pain Id like to ONLY refer to wrkbook2 to copy the sheet over, and from then on, use the code on the copysheet in wrkbook1.

thanks again

[ This Message was edited by: robfo0 on 2002-04-18 19:28 ]
robfo0 is offline   Reply With Quote
Old Apr 18th, 2002, 09:07 PM   #6
brettvba
MrExcel MVP
 
Join Date: Feb 2002
Location: Christchurch New Zealand
Posts: 1,030
Default

Sub opencopy()
currbook = ActiveWorkbook.Name

'Open
Workbooks.Open Filename:= _
"w:book2.xls" ', ReadOnly:=True
Sheets("copysheet").Select
Sheets("copysheet").Move Before:=Workbooks(currbook).Worksheets(Worksheets.Count)
Sheets("copysheet").Unprotect

Application.Run (currbook) & "!sheet4.butt*******"
' assuming you have 3 sheets in book1
End Sub

Hope that helps it works for me depends on how many sheets you have in book 1 or your book name..
brettvba is offline   Reply With Quote
Old Apr 18th, 2002, 09:10 PM   #7
brettvba
MrExcel MVP
 
Join Date: Feb 2002
Location: Christchurch New Zealand
Posts: 1,030
Default

or if you go into book2 and change the "(name)" of copysheet to copysheet you can run the macro like this

Sub opencopy()
currbook = ActiveWorkbook.Name

'Open
Workbooks.Open Filename:= _
"w:book2.xls" ', ReadOnly:=True
Sheets("copysheet").Select
Sheets("copysheet").Move Before:=Workbooks(currbook).Worksheets(Worksheets.Count)
Sheets("copysheet").Unprotect

Application.Run (currbook) & "!copysheet.butt*******"
' assuming you have 3 sheets in book1
End Sub
brettvba is offline   Reply With Quote
Old Apr 18th, 2002, 09:16 PM   #8
robfo0
Board Regular
 
Join Date: Feb 2002
Location: Stockton, California
Posts: 281
Default

yes! the 2nd is what i was trying to do, works great now, thanks so very much
robfo0 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:31 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