ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Open file based on yesterday's date (https://www.excelbanter.com/excel-programming/339003-open-file-based-yesterdays-date.html)

ForSale[_59_]

Open file based on yesterday's date
 

Hello,
Everyday when I come in I have to open the an excel file from th
previous day. For instance, today I had to open “workbook 8-30.xls
and tomorrow I’ll have to open “workbook 9-1.xls”. I was thinkin
there might be a way to have this open for me automatically when I ope
Excel. Any ideas on what the macro for this should look like?
Thanks

--
ForSal
-----------------------------------------------------------------------
ForSale's Profile: http://www.excelforum.com/member.php...fo&userid=1189
View this thread: http://www.excelforum.com/showthread.php?threadid=40133


Rowan[_4_]

Open file based on yesterday's date
 
Add this to the ThisWorkbook module of your PERSONAL.xls file;

Private Sub Workbook_Open()
Dim flname As String
Dim path As String

path = "C:/Temp/"

On Error Resume Next
flname = Month(Date) & "-" & Day(Date) & ".xls"
Workbooks.Open (path & flname)
On Error GoTo 0

End Sub

Hope this helps
Rowan

"ForSale" wrote:


Hello,
Everyday when I come in I have to open the an excel file from the
previous day. For instance, today I had to open €œworkbook 8-30.xls€
and tomorrow Ill have to open €œworkbook 9-1.xls€. I was thinking
there might be a way to have this open for me automatically when I open
Excel. Any ideas on what the macro for this should look like?
Thanks.


--
ForSale
------------------------------------------------------------------------
ForSale's Profile: http://www.excelforum.com/member.php...o&userid=11896
View this thread: http://www.excelforum.com/showthread...hreadid=401337



Dave Peterson

Open file based on yesterday's date
 
I think that the OP wanted yesterday's date. So this line:

flname = Month(Date) & "-" & Day(Date) & ".xls"
could be:
flname = Month(Date-1) & "-" & Day(Date-1) & ".xls"
or just:
flname = format(date-1,"m-d") & ".xls"

Rowan wrote:

Add this to the ThisWorkbook module of your PERSONAL.xls file;

Private Sub Workbook_Open()
Dim flname As String
Dim path As String

path = "C:/Temp/"

On Error Resume Next
flname = Month(Date) & "-" & Day(Date) & ".xls"
Workbooks.Open (path & flname)
On Error GoTo 0

End Sub

Hope this helps
Rowan

"ForSale" wrote:


Hello,
Everyday when I come in I have to open the an excel file from the
previous day. For instance, today I had to open €œworkbook 8-30.xls€
and tomorrow Ill have to open €œworkbook 9-1.xls€. I was thinking
there might be a way to have this open for me automatically when I open
Excel. Any ideas on what the macro for this should look like?
Thanks.


--
ForSale
------------------------------------------------------------------------
ForSale's Profile: http://www.excelforum.com/member.php...o&userid=11896
View this thread: http://www.excelforum.com/showthread...hreadid=401337



--

Dave Peterson


All times are GMT +1. The time now is 03:17 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com