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 - thisworkbook.path
VBA code running but not having effect
VBA-style range selection in Excel
Sorting Excel data
MS Office - ActiveX Buttons switching places
Not able to access excel file
Sending Excel VBA email
Excel VBA 'If Then Else' Statement fails
How to run sub procedure [closed]
How to compare data where data matches (or doesn't match) on two columns?
Left vlookup error
GAS - Script to duplicate a script
Convert Excel VBA Analysis ToolPack “Fourier” Sub into a UDF Function
Excel VBA look through sheets and copy column range to another sheet
VBA/macro to move rows to various other sheets automatically
Macro to color the row nos and copy colored rows to another sheet