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 May 17th, 2002, 02:35 PM   #1
James
Board Regular
 
Join Date: Feb 2002
Location: Huntington Beach, CA USA
Posts: 327
Default

My Code:

Private Sub Workbook_Open()
ThisWorkbook.IsAddin = False
End Sub

Private Sub Workbook_BeforeClose(Cancel As Boolean)
This Workbook.IsAddIn = True
End Sub

With the above code, if you choose to disable the macros the file will not open.

Private Sub Workbook_BeforeSave(BYVal SaveAsUI As Boolean, Cancel As Boolean)
If ThisWorkbook.Saved = False Then
MsgBox"changes not saved", vbOKOnly
Cancel = True
End If
End Sub

With the above code, it cancels "saving" the Workbook.

My headache is that i can't combine them and get them both to work in unison.

Regards,
James




_________________


[ This Message was edited by: James on 2002-05-17 18:29 ]

[ This Message was edited by: James on 2002-05-17 20:26 ]
James is offline   Reply With Quote
Old May 17th, 2002, 06:59 PM   #2
NateO
Legend
 
NateO's Avatar
 
Join Date: Feb 2002
Location: Minneapolis, Mn, USA
Posts: 9,704
Default

James, just to clarify, are you trying to not allow users to save the file until close, then allow them to save? I got this impression when you set the file at close. With a little more clarity on the concept, we can get this conflict resolved.

Also, in your post you have an inadvertant space in "thisworkbook" in your beforeclose procedure.

_________________
Cheers, NateO

[ This Message was edited by: NateO on 2002-05-17 19:29 ]
NateO is offline   Reply With Quote
Old May 17th, 2002, 07:11 PM   #3
James
Board Regular
 
Join Date: Feb 2002
Location: Huntington Beach, CA USA
Posts: 327
Default

Hi Nate,

Edited my original, hopefully i clarified what i am trying to achive.

Regards,
James

[ This Message was edited by: James on 2002-05-17 18:33 ]
James is offline   Reply With Quote
Old May 18th, 2002, 12:26 AM   #4
dsnbld
Board Regular
 
Join Date: May 2002
Posts: 206
Default

Hi James,

Set the workbook to run as AddIn:

Private Sub Workbook_BeforeClose(Cancel As Boolean)
ThisWorkbook.IsAddin = True
End Sub

Save & Close (and save again at prompt)

Re-open workbook and enable macros at prompt. Book window is hidden, but you can still open VBA, delete the above (hit save in VBA after deleting) and enter the following:


Private Sub Workbook_Open()
ThisWorkbook.IsAddin = False
End Sub

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
If ThisWorkbook.Saved = False Then
Msg = "Saving Changes Is Disabled In Evaluation Version"
Msg = MsgBox(Msg, vbOKOnly + vbExclamation)
Cancel = True
'Interupt here when saving this code for the first time. I type "bug" to interupt.
'Debug (delete bug) and reset- after reset the save process will continue.
'In future you can manually set ThisWorkbook.Saved property to True to save changes.
End If
End Sub

In the future when you manually set the ThisWorkbook.Saved property to True to save your changes, the "Saving Changes Is Disabled" may come up, but click OK and immediately hit save again- and it will save. I've put this through the ringer and it works everytime.

Win98, Office 2K.

[ This Message was edited by: dsnbld on 2002-05-18 05:58 ]
dsnbld is offline   Reply With Quote
Old May 18th, 2002, 11:50 AM   #5
dsnbld
Board Regular
 
Join Date: May 2002
Posts: 206
Default

James, I sent this clarification to you. I'm posting it here for anyone else who might want it.


Private Sub Workbook_BeforeClose(Cancel As Boolean) 'this is all you do to start!
ThisWorkbook.IsAddin = True
End Sub

Save (not save as) & Close (close will ask if you want to save your changes- yes).

I'm in the habit of closing Excel after making and saving changes to a file and want to re-open it.

Re-open workbook and ENABLE MACROS at prompt. Book window is hidden, but you can still open VBA,
* delete the above procedure
* click VBA Save (this is a must)
* then enter the following code
* after you enter the code type the word "bug" between Cancel = True and End If
* click save (this will trigger the debugger because of the "bug")
* delete bug and click reset (the save process will continue because of the interuption)
* next time you open the file your set


Private Sub Workbook_Open()
ThisWorkbook.IsAddin = False
End Sub

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
If ThisWorkbook.Saved = False Then
Msg = "Saving Changes Is Disabled In Evaluation Version"
Msg = MsgBox(Msg, vbOKOnly + vbExclamation)
Cancel = True
'Interupt here when saving this code for the first time. I type "bug" to interupt.
'Debug (delete bug) and reset- after reset the save process will continue.
'In future you can manually set ThisWorkbook.Saved property to True to save changes.
End If
End Sub

In the future when you manually set the ThisWorkbook.Saved property to True to save your changes, the "Saving Changes Is Disabled" may come up, but click OK and immediately hit save again- and it will save. I've put this through the ringer and it works everytime.

Win98, Office 2K.
dsnbld 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 09:00 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