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 22nd, 2002, 01:18 AM   #1
Brian
Board Regular
 
Join Date: Apr 2002
Posts: 113
Default

VBA code copies specified sheets from one workbook to another and then e-mails the new workbook.

The only method I have found to name the workbook is to save it. If not it just gets the default "Book1.xls" name.

True? or is there another way to rename the workbook before sending it?

Thanks,

Brian
Brian is offline   Reply With Quote
Old May 22nd, 2002, 01:59 AM   #2
Colo
MrExcel MVP
 
Colo's Avatar
 
Join Date: Mar 2002
Location: Kobe, Japan
Posts: 1,420
Default

Quote:
On 2002-05-22 00:18, Brian wrote:
VBA code copies specified sheets from one workbook to another and then e-mails the new workbook.

The only method I have found to name the workbook is to save it. If not it just gets the default "Book1.xls" name.

True? or is there another way to rename the workbook before sending it?

Thanks,

Brian
Hi Brian,

As far as I know, it needs to save for change name of a book.

Another information?
__________________
Regards,

Masaru Kaji aka Colo - Ex Microsoft MVP Since 2004 -2009
Colo is offline   Reply With Quote
Old May 22nd, 2002, 02:48 AM   #3
Tom Schreiner
Board Regular
 
Join Date: Mar 2002
Location: Cincinnati, Ohio, USA
Posts: 6,824
Default

Good morning Colo!

Brian,
I tried to rename the open workbook using an class which works with application level events and no dice. The workbook name property is read only it seems.
If your only problem is a bunch of workbooks, maybe you could add a bit of code to simply delete the newly created book?


Sub TryThisOutBrian()
Dim KillThisFile As String
Dim FileNameToSend As String
'assign the name to your new wb however you wish in your code
FileNameToSend = "SendThenKill"
'perform your copy from the activeworkbook
Sheets("Sheet1").Copy
'saveas to rename the new wb
ActiveWorkbook.SaveAs "C:" & FileNameToSend
'collect the string for the full path to later
'delete this file
KillThisFile = ActiveWorkbook.FullName
'collect the name of the book to close
CloseThisFile = ActiveWorkbook.Name

'your code

'after emailing, close and then kill the workbook
'which is no longer needed.
Workbooks(FileNameToSend).Close savechanges:=False
Kill KillThisFile
End Sub


Tom
Tom Schreiner is offline   Reply With Quote
Old May 22nd, 2002, 03:04 AM   #4
Sbirro Cornuto
Board Regular
 
Join Date: Mar 2002
Location: Little Italy
Posts: 93
Default

If I just may have my say in this, I'll say that Toms trix to this matter are the best you can ask for.

There doesn't seem to be anyway around those RO properties, I myself have been trying everything.

Once though I ran in to Excel application that seem to be able to change the name on the fly w/o saving the book. Don't know if it only gave that impression or how the hell it was done (protected code).
Sbirro Cornuto is offline   Reply With Quote
Old May 22nd, 2002, 03:19 AM   #5
Mudface
MrExcel MVP
 
Join Date: Feb 2002
Location: Sunny, spring-like Hull
Posts: 3,339
Default

Sbirro- was it just changing the windows caption property, perhaps? I do that sometimes to make sure I'm doing stuff on the 'right' workbook. eg-

With WorkBooks.Add
.Windows(1).Caption = "Destination"
End With

' later on
Windows("Destination").Activate
' do stuff
Mudface is offline   Reply With Quote
Old May 22nd, 2002, 03:19 AM   #6
Colo
MrExcel MVP
 
Colo's Avatar
 
Join Date: Mar 2002
Location: Kobe, Japan
Posts: 1,420
Default

Hi TsTom,

That's a good idea!!
__________________
Regards,

Masaru Kaji aka Colo - Ex Microsoft MVP Since 2004 -2009
Colo is offline   Reply With Quote
Old May 22nd, 2002, 03:36 AM   #7
Sbirro Cornuto
Board Regular
 
Join Date: Mar 2002
Location: Little Italy
Posts: 93
Default

Nope, it wasn't that caption thing, I've used it time to time to show the percentage done by some long task doing application. It's a nifty way to see the progress of an app with window minimized, when it's all done there's a Msgbox in my code, it makes the taskbar icon (is that what it's called?) flash until you hit it, then it prompts what ever is in your Msgbox.

[ This Message was edited by: Sbirro Cornuto on 2002-05-22 02:38 ]
Sbirro Cornuto is offline   Reply With Quote
Old May 22nd, 2002, 10:44 AM   #8
Brian
Board Regular
 
Join Date: Apr 2002
Posts: 113
Default

Wow, thanks for all the effort.

It is understandable that the filename cannot be changed without saving it, but i wish Excel had a "Before_Create_File_Event" where we could control the filename.

Note: Application.GetSaveAsFilename will return a string for the name, but the filename will not change until the file is saved.

Note: I can get away from Book1, Book2 by creating the new file from a template, then I get templatename1, templatename2.

This would not be too bad because then I only save a template once the first time someone runs the code and not for every e-mail.

My other option would be to use keystrokes to select the file in the open message and edit the filename, but that sounds weak and subject to problems if they use a different mail program.

However, I'll probably either skip the rename or save the new file before it has data and then delete it later. (The reason I don't like this is some users that are apprehensive of macros will wonder why their hard drive is active, which will scare them.)

Thanks again,

Brian
Brian 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:03 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