Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 100
Default Open File with name incorporating ~yesterday's date

Excel Experts,

Each day, I want to open a file with path and name in the format of

T:\Statements\MMM\MCNC MMDDYY
where MMM=Current month and MMDDYY is the last business day

For example the file I opened this morning was:

T\Statements\SEP\MCNC 092005

For reference, I've used the following code to save a file with today's date
ActiveWorkbook.SaveAs Filename:= _
"T\Statements\MyFile" & Format(Date, "yymmdd") & ".xls"

Also, I've used the following code to put the date of the last business date
in a cell:
ActiveCell.FormulaR1C1 = "=TODAY()-IF(WEEKDAY(TODAY())=2,3,1)"

So essentially what I need to do is to replace the code
Format(Date,"yymmdd") , which indicates today's date
with code that will indicate the last business day

I tried using the code I used for the formula into a FileOpen statement but
it didn't work.

Can this be done?

Thanks,
Alan

--
achidsey
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,092
Default Open File with name incorporating ~yesterday's date

Try this:

Sub OpenFile()
Dim Tday As Date
Dim Tmonth As String
Dim Yday As String

Tday = Date - 1
Yday = Format(Tday, "mm/dd/yy")
Tmonth = Format(Format(Tday, "mmm"), "")
Yday = Replace(Yday, "/", "")
Workbooks.Open Filename:="T:\Statements\" & Tmonth & "\MCNC " & Yday &
".xls"
End Sub

Mike F
"achidsey" (notmorespam) wrote in message
...
Excel Experts,

Each day, I want to open a file with path and name in the format of

T:\Statements\MMM\MCNC MMDDYY
where MMM=Current month and MMDDYY is the last business day

For example the file I opened this morning was:

T\Statements\SEP\MCNC 092005

For reference, I've used the following code to save a file with today's
date
ActiveWorkbook.SaveAs Filename:= _
"T\Statements\MyFile" & Format(Date, "yymmdd") & ".xls"

Also, I've used the following code to put the date of the last business
date
in a cell:
ActiveCell.FormulaR1C1 = "=TODAY()-IF(WEEKDAY(TODAY())=2,3,1)"

So essentially what I need to do is to replace the code
Format(Date,"yymmdd") , which indicates today's date
with code that will indicate the last business day

I tried using the code I used for the formula into a FileOpen statement
but
it didn't work.

Can this be done?

Thanks,
Alan

--
achidsey



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Open File with name incorporating ~yesterday's date

Hi Alan,

Try:

'===================
Sub aTester3()
Dim sStr As String
Const strPrefix As String = "MCNC "
Const strPath As String = "T:\Statements\MMM\"

sStr = Evaluate("=TODAY()-IF(WEEKDAY(TODAY())=2,3,1)")
sStr = Format(sStr, "yymmdd")

Workbooks.Open (strPath & strPrefix & sStr)

End Sub
'===================


---
Regards,
Norman



"achidsey" (notmorespam) wrote in message
...
Excel Experts,

Each day, I want to open a file with path and name in the format of

T:\Statements\MMM\MCNC MMDDYY
where MMM=Current month and MMDDYY is the last business day

For example the file I opened this morning was:

T\Statements\SEP\MCNC 092005

For reference, I've used the following code to save a file with today's
date
ActiveWorkbook.SaveAs Filename:= _
"T\Statements\MyFile" & Format(Date, "yymmdd") & ".xls"

Also, I've used the following code to put the date of the last business
date
in a cell:
ActiveCell.FormulaR1C1 = "=TODAY()-IF(WEEKDAY(TODAY())=2,3,1)"

So essentially what I need to do is to replace the code
Format(Date,"yymmdd") , which indicates today's date
with code that will indicate the last business day

I tried using the code I used for the formula into a FileOpen statement
but
it didn't work.

Can this be done?

Thanks,
Alan

--
achidsey



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Display yesterday's date but only for weekdays? totalnatal Excel Worksheet Functions 8 November 15th 12 04:43 PM
Date open file with date saved Rita Excel Worksheet Functions 3 April 23rd 09 03:13 PM
Can I restore yesterday's file? Stress Excel Discussion (Misc queries) 4 December 27th 07 06:29 PM
Open file based on yesterday's date ForSale[_59_] Excel Programming 2 September 2nd 05 06:13 AM
Incorporating DATE into formula sylink Excel Programming 5 August 4th 05 03:28 PM


All times are GMT +1. The time now is 12:02 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"