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 22nd, 2002, 08:31 AM   #1
Corman
New Member
 
Join Date: Mar 2002
Posts: 23
Default

Hello.

I have a macro, ran from a control button on the worksheet, that unprotects the worksheet, then resizes an object located on a chart, prints a range, then re-protects the worksheet.

When I press the button for the macro, only the printing is done (it does not resize the object). But, when I run the code line by line in the VB editor, it runs properly and resizes the object!

This is the code I'm using:

-----------
Sub PrintReport()

' Unprotect Worksheet
ActiveCell.Activate
Application.ScreenUpdating = False
Sheets("Report").Activate
ActiveSheet.Unprotect Password:="earth"

' Make sure chart legend is in correct position
Sheets("Report").Activate
ActiveSheet.ChartObjects("Chart 11").Activate
ActiveChart.ChartArea.Select
ActiveChart.Shapes("Group 23").Select
Selection.Width = 413
Selection.Height = 45
Selection.ShapeRange.Left = 65
Selection.ShapeRange.Top = 10

' Print completed report sheet
Sheets("Report").Activate
Range("A1:I56").Select
ActiveSheet.PageSetup.PrintArea = "$A$1:$I$56"
ActiveWindow.SelectedSheets.PrintOut Copies:=1
Range("E2:I4").Select

' Re-protect Worksheet
Application.ScreenUpdating = True
ActiveSheet.Protect Password:="earth"

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

Any ideas as to why it won't run properly? I'm using XL97.

Thanks,
Corey

Corman is offline   Reply With Quote
Old Mar 22nd, 2002, 08:32 AM   #2
Dave Hawley
Banned
 
Join Date: Feb 2002
Posts: 1,582
Default

Hi Corey


Set the TakeFocus******* Property of the CommandButton to False.


Dave Hawley is offline   Reply With Quote
Old Mar 22nd, 2002, 08:37 AM   #3
Corman
New Member
 
Join Date: Mar 2002
Posts: 23
Default

Thanks for the reply Dave.

Changed the focus for the button to false, but it still doesn't work.

Any other ideas?

Corey
Corman is offline   Reply With Quote
Old Mar 22nd, 2002, 08:45 AM   #4
Tom Schreiner
Board Regular
 
Join Date: Mar 2002
Location: Cincinnati, Ohio, USA
Posts: 6,824
Default

I'm no Excel expert but I have had problems similiar to yours from printing to missing formats. The best solution I have come across is to slow the macro down inbetween certain events. Especially repaints.

Copy this little sub into a standard module
Listed below

Slow down things a bit and that might help you.

This call to the sub would pause for about a second SD 1
You can use SD .1 to pause for one tenth of a second or just about any other measurement you need.


Sub SD(LenTime)
Dim Start
Start = Timer + LenTime
Do While Timer < Start
If Timer = 0 Then Start = _
Timer + 1
DoEvents
Loop
End Sub


[ This Message was edited by: TsTom on 2002-03-22 07:46 ]
Tom Schreiner is offline   Reply With Quote
Old Mar 22nd, 2002, 08:49 AM   #5
Dave Hawley
Banned
 
Join Date: Feb 2002
Posts: 1,582
Default


It could be because you are Activating the Report sheet, but not selecting it.
Try:

ub PrintReport()

' Unprotect Worksheet


Sheets("Report").Unprotect Password:="earth"

Application.ScreenUpdating = False
' Make sure chart legend is in correct position
With Sheets("Report")
.Select
.ChartObjects("Chart 11").Activate
.ChartArea.Select
End With
ActiveChart.Shapes("Group 23").Select
Selection.Width = 413
Selection.Height = 45
Selection.ShapeRange.Left = 65
Selection.ShapeRange.Top = 10

' Print completed report sheet
Sheets("Report").Activate
Range("A1:I56").Select
ActiveSheet.PageSetup.PrintArea = "$A$1:$I$56"
ActiveWindow.SelectedSheets.PrintOut Copies:=1
Range("E2:I4").Select

' Re-protect Worksheet
Application.ScreenUpdating = True
ActiveSheet.Protect Password:="earth"

End Sub
Dave Hawley is offline   Reply With Quote
Old Mar 22nd, 2002, 09:10 AM   #6
Corman
New Member
 
Join Date: Mar 2002
Posts: 23
Default

hmmm. Activating the sheet didn't help.


TsTom, how would I code to call the SD routine?

I tried to put this in the code above, with the SD routine in it's own module:

LenTime = 1
Call SD

But that didn't seem to work.

I even tried to put the resizing on it's own button, but no luck.

One thing that may help you guys: I originally had the code for resizing associated with an OK button for a userform, and it worked great. But I'd like the resizing to occur just before printing (I could try to have the PrintReport button connect to a userform that asks if I want to print, then have the resize code run if ok is pressed, but there has to be a better way to do it!).

Looking forward to your other ideas guys!

Corey


Corman is offline   Reply With Quote
Old Mar 22nd, 2002, 09:21 AM   #7
Dave Hawley
Banned
 
Join Date: Feb 2002
Posts: 1,582
Default

Corey, I think it maybe because you are using a CommanDButton from the Control toolbox. These become part of the sheet so are you calling this macro?
eg Run "PrintReport"

Go with a CommandButton from the Forms toolbar, much better for something like this.


Dave Hawley is offline   Reply With Quote
Old Mar 22nd, 2002, 09:25 AM   #8
Tom Schreiner
Board Regular
 
Join Date: Mar 2002
Location: Cincinnati, Ohio, USA
Posts: 6,824
Default

To call for a one second pause type:
SD 1 in any procedure in your project

The value is passed to the Sub without
pre-declaring LenTime.

SD .1 for a 1/10 sec pause

ect ect
Tom Schreiner is offline   Reply With Quote
Old Mar 22nd, 2002, 09:41 AM   #9
Corman
New Member
 
Join Date: Mar 2002
Posts: 23
Default

Dave,

I created a new button from the forms toolbar, and attached the code to it, but when I run it I get an error for the following line of code:

"Object doesn't suuport this property or method"

error on this coding: ChartArea.Select

Corey


Corman 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 07:59 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