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 Feb 26th, 2002, 07:10 AM   #1
Audiojoe
Board Regular
 
Join Date: Feb 2002
Location: Where the wild roses grow
Posts: 285
Default


If I want to set a macro to save a file as a certain date, how do I do it?

At the moment, the macro copies a block of data, pastes it into a template, then I want it to save that template as last week's date. For instance, the file template is called Weekly Report Template, when the macro saves it I need it be saved as:

Weekly Report - 18th-24th February 2002

as that is the period that the report covers. However, of course NEXT week it will have to save it as:

Weekly Report - 25th Feb-3rd March 2002

and so on....

Can anyone help me?


Audiojoe is offline   Reply With Quote
Old Feb 26th, 2002, 07:33 AM   #2
pilot
Board Regular
 
Join Date: Feb 2002
Location: Houston, TX
Posts: 303
Default

Quote:
On 2002-02-26 06:10, Audiojoe wrote:

If I want to set a macro to save a file as a certain date, how do I do it?

At the moment, the macro copies a block of data, pastes it into a template, then I want it to save that template as last week's date. For instance, the file template is called Weekly Report Template, when the macro saves it I need it be saved as:

Weekly Report - 18th-24th February 2002

as that is the period that the report covers. However, of course NEXT week it will have to save it as:

Weekly Report - 25th Feb-3rd March 2002

and so on....

Can anyone help me?


What is the relationship between the date you run the macro and the dates of the material being saved? For example, for
Weekly Report - 18th-24th February 2002
will the save take place on Feb 25th? Feb 26th? Some varied date but always during M-F after the week being saved?
pilot is offline   Reply With Quote
Old Feb 26th, 2002, 07:35 AM   #3
Juan Pablo González
MrExcel MVP
 
Join Date: Feb 2002
Location: Bogota, Colombia
Posts: 11,927
Default

Well, try this.

Put this UDF somewhere in the module.

Code:
Function LastWeek(Dt As Date) As String
Dim T1 As Long
Dim T2 As Long
T1 = Dt - (WeekDay(Dt, vbMonday) - 1)
T2 = T1 + 6

LastWeek = Format(T1, IIF(Month(T1) <> Month(T2),"dd mmm","dd")) & "-" & Format(T2, "dd mmmm yyyy")
End Function
This function accepts a DATE as a parameter, and returns the WEEK of that date (Mon - Sun) trying to resemble your format.

Then, you could use it like this:

ActiveWorkbook.SaveAs "Weekly Report " & LastWeek(Date-7) & ".xls"

I think that covers it.

_________________
Regards,

Juan Pablo G.
MrExcel.com Consulting

[ This Message was edited by: Juan Pablo G. on 2002-02-26 06:36 ]
Juan Pablo González is offline   Reply With Quote
Old Feb 26th, 2002, 07:36 AM   #4
Audiojoe
Board Regular
 
Join Date: Feb 2002
Location: Where the wild roses grow
Posts: 285
Default

It will always be on the day after the week has finished, for example:

18th-24th Feb 2002

would have been saved on the 25th
Audiojoe is offline   Reply With Quote
Old Feb 26th, 2002, 07:38 AM   #5
Juan Pablo González
MrExcel MVP
 
Join Date: Feb 2002
Location: Bogota, Colombia
Posts: 11,927
Default

Quote:
On 2002-02-26 06:36, Audiojoe wrote:
It will always be on the day after the week has finished, for example:

18th-24th Feb 2002

would have been saved on the 25th
Look at my reply, I think that should solve your problem.
__________________
Regards,

Juan Pablo González
http://www.juanpg.com
Juan Pablo González is offline   Reply With Quote
Old Feb 26th, 2002, 07:43 AM   #6
Audiojoe
Board Regular
 
Join Date: Feb 2002
Location: Where the wild roses grow
Posts: 285
Default

Thanks for getting back to me so quickly, I'll get it tried out

Regards
Audiojoe is offline   Reply With Quote
Old Feb 26th, 2002, 08:11 AM   #7
Audiojoe
Board Regular
 
Join Date: Feb 2002
Location: Where the wild roses grow
Posts: 285
Default

OK, I'm getting a little lost now, what is wrong with this? I guess it's glaring but I'm new to this racket...


Sub savingcopiedscripts()

' savingcopiedscripts Macro
' Macro recorded 26/02/02 by aroche

Function Lastweek(Dt As Date) As String
Dim t1 As Long
Dim t2 As Long
t1 = Dt - (WeekDay(Dt, vbMonday) - 1)
t2 = t1 + 6

Last week = Format(t1, IIf(Month(t1) <> Month(t2), "dd mmm", "dd")) & "-"

ChDir "H:Stats"
ActiveWorkbook.SaveAs FileName:="H:Stats", FileFormat:= _
xlNormal, Password:="", WriteResPassword:="", ReadOnlyRecommended:=False _
, CreateBackup:=False

End Function
Audiojoe is offline   Reply With Quote
Old Feb 26th, 2002, 08:24 AM   #8
Audiojoe
Board Regular
 
Join Date: Feb 2002
Location: Where the wild roses grow
Posts: 285
Default

Hi, does anyone know how on earth I can fix the above?

Audiojoe is offline   Reply With Quote
Old Feb 26th, 2002, 08:42 AM   #9
Audiojoe
Board Regular
 
Join Date: Feb 2002
Location: Where the wild roses grow
Posts: 285
Default

Anyone?
Audiojoe is offline   Reply With Quote
Old Feb 26th, 2002, 08:48 AM   #10
Juan Pablo González
MrExcel MVP
 
Join Date: Feb 2002
Location: Bogota, Colombia
Posts: 11,927
Default

Do you really need to post every 3 seconds if no one has answered ?

The problem is that you're using a function inside of a Sub. Put it like this:

Function LastWeek....
....
End Function

Sub YourSub()

.....

End Sub
__________________
Regards,

Juan Pablo González
http://www.juanpg.com
Juan Pablo González 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 06:00 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