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
How to update a specific row of a table in Excel using Microsoft Graph?
columns' values based on specific rows in pivot table excel
VBA Adding cells from one sheet to another by cell
Searchng a sheet for a value and returning row & column numbers
How to take a control of specific cell of XL?
Vlookup exact text on a cell text string
HTTP GET responds with empty body, downloads excel document in IE
VBA replace comma with line break in word?
Excel online sharing
Change cell value based off of selection from ListBox
How to remove hidden quotes
Sorting out data by insert and copy and paste special
Excel VB to create monthly table based on user input
Week number from Date format in excel(Monthwise_Week Number)
Is there a way to connect to an external powerpivot data model from an Excel workbook?
VBA for Sending Outlook Mail from Excel automatically even when workbook is closed [on hold]