excel


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

Related Links

Visual Basic ParamArray args: The formula contains unrecognized text
<Excel-VBA> “Type mismatch” error while copying value from cell into textbox
Loop through a row until blank
Excel Mac 2016 vba fill.Userpicture from range
Vlookup - return multiple values / array in a macro
making end of date shorter in Gantt - Excel
Build 1D array / list in formula by multiplying values for use in AVERAGE()
Error adding numeric to text
Dynamic referencing the UsedRange in VBA
VBA formula does not work properly
Copy&Paste Data Multiple Criteria Excel
How to parse part of a cell containing x.x.x. and copy the data to another cell?
Excel sheet loses formatting and sheet structure
Concatenate part of cell 1 by multiple criteria with all of cell 2, finishing with cell 1’s remainder
Getting VBA to click a button on an addin toolbar… CommandBars?
How do I return data when the condition of two statements are true?

Categories

HOME
c++
github
recaptcha
graphite
payment
kotlin
bloomberg
cakephp-3.0
binary
put
android-gradle
ios8
http-headers
c#-3.0
pivot-table
apostrophe-cms
bpm
video-processing
adodb-php
border
web-component
skybot
markup
pad
zillow
image-comparison
react-apollo
xbuild
gembox-document
ctype
angular-openlayers
bing-api
pi4j
gtm-database
drools-fusion
infowindow
live
gearman
tablet
dos
angular2-http
gooddata
digestive-functors
fpu
templating
gulp-usemin
background-position
data-processing
ifttt
api-manager
wso2-appm
knockout-validation
prime-factoring
csla
angularjs-service
vorlon
date-formatting
code-signing-entitlements
nslog
canonical-link
aide-ide
google-api-webmasters
metamodel
webtorrent
markov-models
ubuntu-15.10
throttle
grape
openoffice-writer
spawn-fcgi
sos
anonymity
octopress
gridster
ooyala
mks-integrity
realbasic
gridsplitter
tess-two
wordpress-4.5
acl2
angularjs-ng-options
fluid-layout
android-bundle
cordova-chrome-app
cloudcontrol
custom-validators
event-loop
t4-toolbox
openni
grunt-contrib-cssmin
review
ember-testing
linux-capabilities
ember-qunit
data-sharing
out
bonsaijs
jform-designer
mashup
stockquotes
android-3.0-honeycomb
scite
rounded-corners
mib
slimv
java-service-wrapper
cgimagesource
customvalidator
codeigniter-datamapper
hibernate-annotations
umbraco5
xla
comdlg32
o3d

Resources

Encrypt Message



code
soft
python
ios
c
html
jquery
cloud
mobile