How to exclude weekends while opening file in VBA?
everyday one file will create with date as previous working day. Example, (05/16/2017, Tuesday) file will create with date as 05/15/2017, Monday. whereas on 05/15/2017, Monday file will create with date as 05/12/2017. I am trying to open file using VBA with the below code, file name Format="C:\users\Duke\report'05/15/2017'.XLS" sub OpenFile() Const fpath As String = "C:\users\Duke\Report" Dim fname As String fname = Format(Date - (Weekday((Date),Vbmonday) - 1), "yyyy-mm-dd") fname = "'" & fname & "'" & ".XLS" Dim path As String path = fpath & fname end () But it is not working, Please suggest.
VBA does not have a built in method to handle workdays. But the following might compute the desired date, if your code only runs M-F and SS are weekends: Dim X As Long X = IIf(Weekday(Date) = vbMonday, 3, 1) fname = Format(Date - X, "yyyy-mm-dd") If your code might also run on the weekends, then you will have to define what you want to happen, in that event
VBA: Loop does not include last 2 rows
How to use variable string in index formula in VBA?
Calculate SUM based on date
Need to transpose multiple excel rows to columns [duplicate]
Text to Time with Milliseconds
Exclude rows with formulas from range in macro
Formating excel percentage decimals
Excel VBA - Looking for Strings in “Text Block” , then look in the next
make one cell value 0 if other cell value > 0 using excel
Conditional AGGREGATE/Median in Excel 2010
Excel VBA filtering a column and then copying each item in the area collection to a matching row
Excel addition of multiple numbers in single cell
How do I autofill code in VBA?
Use excel VBA to update master list based on user input data
Change number format of a cell which inlude currecny using visual basic
Access reading Excel VBA date in US format