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 Mar 20th, 2002, 01:29 PM   #1
kenstr
New Member
 
Join Date: Mar 2002
Location: Raleigh, NC USA
Posts: 11
Default

Preamble: Workbook with 3 sheets and the following code in it

Private Sub Workbook_Open()

ThisWorkbook.Worksheets("Sheet2").Select
ActiveSheet.Range("A1").Select
ActiveCell = "this text should be in the second sheet cell a1"
ActiveWindow.Zoom = (Application.UsableWidth / Range("a1:o1").Width) * 100
Application.DisplayFullScreen = True

End Sub


The code works fine when opened directly. If the workbook is opend via automation (say with VB), it will "run" but nothing really works the same.

Opened in VB as simple as possible:

Set mobjExcel = CreateObject("Excel.Application")
File = "c:OnOpen_sample.xls"
mobjExcel.Workbooks.Open File, 0, False, , , , True


This is driving me nuts...
kenstr is offline   Reply With Quote
Old Mar 20th, 2002, 04:33 PM   #2
Al Chara
MrExcel MVP
 
Join Date: Feb 2002
Location: Monterrey, Mexico
Posts: 1,433
Default

Try the following code to open your workbook:

ChDir ("c:\")
Workbooks.Open "OnOpen_sample.XLS"
__________________
Kind regards,

Al Chara
Al Chara is offline   Reply With Quote
Old Mar 20th, 2002, 07:05 PM   #3
HunterN
Board Regular
 
HunterN's Avatar
 
Join Date: Mar 2002
Location: Maryland
Posts: 424
Default

Your problem sounds just like mine!
I have two workbooks. Seperately they both
work fine. But when I want the first workbook to call the second workbook, the open works fine but the rest of the macro does not work like it should.

If you find a help (that works) please let me know. Thanks
HunterN is offline   Reply With Quote
Old Mar 20th, 2002, 11:05 PM   #4
Russell Hauf
MrExcel MVP
 
Russell Hauf's Avatar
 
Join Date: Feb 2002
Location: Portland, OR USA
Posts: 1,374
Default

What do you mean by "nothing really works the same"? What exactly does it do when it is opened?
Russell Hauf is offline   Reply With Quote
Old Mar 21st, 2002, 08:25 AM   #5
kenstr
New Member
 
Join Date: Mar 2002
Location: Raleigh, NC USA
Posts: 11
Default

Thanks for the replies, but I think I need to explain further.

If opened directly in excel results are:
1.Text is placed in sheet 2 cell a1 and is selected
2. window is zoomed in and excel is full screen

If opened via automation results are:
1. Text is placed in cell a1 of whatever the last viewed sheet was.
2. no zoom and no full screen and no sheet1 cell a1 selected.

Basically nothing at the application. level works at all and anything refering to activesheet or activeworkbook refers to the wrong sheet. I can even activate sheet 3 and the activesheet still returns whatever the last sheet viewed before it was opened.
kenstr is offline   Reply With Quote
Old Mar 21st, 2002, 08:42 AM   #6
Sbirro Cornuto
Board Regular
 
Join Date: Mar 2002
Location: Little Italy
Posts: 93
Default

You always need to run the Macro from the main code, like Application.Run "yourworkbook.xls!macroname", just open up the WorkBook by code and then run the macro with above mentioned command. After that it gives total control of the WorkBook to it's own macro.
Sbirro Cornuto is offline   Reply With Quote
Old Mar 21st, 2002, 09:22 AM   #7
kenstr
New Member
 
Join Date: Mar 2002
Location: Raleigh, NC USA
Posts: 11
Default

Hey - now were on to something. That sort of works.

The file can be run directly or from inside a VB app. So I moved the code out of the workbook_open and into a sub called initilize. Then added this to the open event:

If Application.UserControl = True Then
initialize
End If

That way the code dosen't double fire if run from the VB app.

I can live with this... now I have to see if we can put a business rule in place "All files with startup code need to work like this to run in our VB app..."

Tks.
kenstr is offline   Reply With Quote
Old Mar 21st, 2002, 09:29 AM   #8
Sbirro Cornuto
Board Regular
 
Join Date: Mar 2002
Location: Little Italy
Posts: 93
Default

That's the case buddy, sorry! No automated starting if you need to run those things from VB also...
Sbirro Cornuto 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 12:48 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