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 Apr 29th, 2002, 11:46 AM   #1
StrangeLuck
New Member
 
Join Date: Mar 2002
Posts: 15
Default

I have a series of file names which have the naming convention mmmddblahblah.xls, whereby mmm refers to the first 3 letters of the month and dd refers to the day of that month. For example, the file for April 7 would be named apr07blahblah.xls.

My question is: Is there a way I could write a macro to open up 7 sequential files (ie. April 27 - May 3) based upon the order of the months and their respective number of days, using the mmmdd part of their names?

Thanks!
StrangeLuck
StrangeLuck is offline   Reply With Quote
Old Apr 29th, 2002, 12:20 PM   #2
Anne Troy
MrExcel MVP
 
Anne Troy's Avatar
 
Join Date: Feb 2002
Location: Allentown, PA
Posts: 2,510
Default

I'm sure it's possible somehow. One of the questions that you'll probably be asked is from which date we'd be starting? Would you want to be able to determine that each time or would it start with, for instance, yesterday?
__________________
~Anne Troy
Anne Troy is offline   Reply With Quote
Old Apr 29th, 2002, 12:33 PM   #3
StrangeLuck
New Member
 
Join Date: Mar 2002
Posts: 15
Default

Quote:
On 2002-04-29 11:20, Dreamboat wrote:
I'm sure it's possible somehow. One of the questions that you'll probably be asked is from which date we'd be starting? Would you want to be able to determine that each time or would it start with, for instance, yesterday?
This would be determined by the calendar weeks. Essentially, I want to have the user input the end date for the week and have the workbooks for the entire week open.

Thanks,
StrangeLuck
StrangeLuck is offline   Reply With Quote
Old Apr 29th, 2002, 12:34 PM   #4
Mark O'Brien
MrExcel MVP
 
Mark O'Brien's Avatar
 
Join Date: Feb 2002
Location: Columbus, OH, USA
Posts: 3,519
Default

Something like this would work (note:: there's some strange stuff in this, someone might want to debug this even more, but it does what you ask):


Public Sub main()
Dim oDate As Date
Dim i As Single
Dim sFileName As String

oDate = #4/27/2002#

For i = 1 To 7
oDate = oDate + 1
sFileName = MonthName(Month(oDate), True) & Format(Day(oDate), "dd") & "Blahblah.xls"
MsgBox sFileName 'Replace this with a "open workbook" statement using sFileName
Next
End Sub


The "strange stuff" is partly to do with the way Excel handles dates and partly to do with the "Format" statement. For some reason, the Format statement was giving my "26" for the first day.

Anyway, I hope this helps.
__________________
Mark O'Brien

Columbus Ohio Celtic Supporters Club
Mark O'Brien is offline   Reply With Quote
Old Apr 29th, 2002, 12:42 PM   #5
dhoffman
New Member
 
Join Date: Apr 2002
Location: Lawrence, KS
Posts: 29
Default

What are you storing in those files? Is it just some generic data in a particular format in each workbook? Have you ever considered storing the data in these files in a single Access database and using queries to load relevant data into a single workbook at runtime?
dhoffman is offline   Reply With Quote
Old Apr 29th, 2002, 12:53 PM   #6
StrangeLuck
New Member
 
Join Date: Mar 2002
Posts: 15
Default

Quote:
On 2002-04-29 11:34, Mark O'Brien wrote:
Something like this would work (note:: there's some strange stuff in this, someone might want to debug this even more, but it does what you ask):


Public Sub main()
Dim oDate As Date
Dim i As Single
Dim sFileName As String

oDate = #4/27/2002#

For i = 1 To 7
oDate = oDate + 1
sFileName = MonthName(Month(oDate), True) & Format(Day(oDate), "dd") & "Blahblah.xls"
MsgBox sFileName 'Replace this with a "open workbook" statement using sFileName
Next
End Sub


The "strange stuff" is partly to do with the way Excel handles dates and partly to do with the "Format" statement. For some reason, the Format statement was giving my "26" for the first day.

Anyway, I hope this helps.
It appears that I cannot use the "MonthName" function, which must be a Excel 2000/2002 option. I am using Excel 97, unfortunately. Can anyone help me further?
StrangeLuck is offline   Reply With Quote
Old Apr 29th, 2002, 12:54 PM   #7
StrangeLuck
New Member
 
Join Date: Mar 2002
Posts: 15
Default

Quote:
On 2002-04-29 11:42, dhoffman wrote:
What are you storing in those files? Is it just some generic data in a particular format in each workbook? Have you ever considered storing the data in these files in a single Access database and using queries to load relevant data into a single workbook at runtime?
Thanks for your input, but I really need to keep these files in the format they currently are. It's work-related.
StrangeLuck is offline   Reply With Quote
Old Apr 29th, 2002, 01:04 PM   #8
Mark O'Brien
MrExcel MVP
 
Mark O'Brien's Avatar
 
Join Date: Feb 2002
Location: Columbus, OH, USA
Posts: 3,519
Default

Well, since you used a smiley, I've created a stunted Excel 97 version of the function copy and paste this into your module:

Private Function MonthName97(ByVal iMonth As Integer)


Select Case iMonth

Case 1
MonthName97 = "Jan"
Case 2
MonthName97 = "Feb"
Case 3
MonthName97 = "Mar"
Case 4
MonthName97 = "Apr"
Case 5
MonthName97 = "May"
Case 6
MonthName97 = "Jun"
Case 7
MonthName97 = "Jul"
Case 8
MonthName97 = "Aug"
Case 9
MonthName97 = "Sep"
Case 10
MonthName97 = "Oct"
Case 11
MonthName97 = "Nov"
Case 12
MonthName97 = "Dec"
End Select

End Function


Then use this line of code (instead of the old one:



sFileName = MonthName97(Month(oDate)) & Format(Day(oDate), "dd") & "Blahblah.xls"


HTH
__________________
Mark O'Brien

Columbus Ohio Celtic Supporters Club
Mark O'Brien is offline   Reply With Quote
Old Apr 29th, 2002, 01:30 PM   #9
StrangeLuck
New Member
 
Join Date: Mar 2002
Posts: 15
Default

Quote:
On 2002-04-29 12:04, Mark O'Brien wrote:
Well, since you used a smiley, I've created a stunted Excel 97 version of the function copy and paste this into your module:

Private Function MonthName97(ByVal iMonth As Integer)


Select Case iMonth

Case 1
MonthName97 = "Jan"
Case 2
MonthName97 = "Feb"
Case 3
MonthName97 = "Mar"
Case 4
MonthName97 = "Apr"
Case 5
MonthName97 = "May"
Case 6
MonthName97 = "Jun"
Case 7
MonthName97 = "Jul"
Case 8
MonthName97 = "Aug"
Case 9
MonthName97 = "Sep"
Case 10
MonthName97 = "Oct"
Case 11
MonthName97 = "Nov"
Case 12
MonthName97 = "Dec"
End Select

End Function


Then use this line of code (instead of the old one:



sFileName = MonthName97(Month(oDate)) & Format(Day(oDate), "dd") & "Blahblah.xls"


HTH
This would work, but I wanted to be able to have the user specify oDate everytime the macro runs.

Thanks,
StrangeLuck
StrangeLuck is offline   Reply With Quote
Old Apr 29th, 2002, 01:38 PM   #10
Mark O'Brien
MrExcel MVP
 
Mark O'Brien's Avatar
 
Join Date: Feb 2002
Location: Columbus, OH, USA
Posts: 3,519
Default

Use this:


oDate = InputBox("Enter a date, mm/dd/yyyy, e.g. 04/23/2002", "Date")

__________________
Mark O'Brien

Columbus Ohio Celtic Supporters Club
Mark O'Brien 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:01 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