![]() |
Error can't Find File
Hi,
I have a macro that opens a file and pulls any outstanding tasks from the previous day. I have a problem when it is a new month because the previous month's file is called MyFileMarch2010. The macro now looks for MyFileApril2010. How do I capture the error and look for the previous month's file if it is the first business day of the month? Any help or suggestions is appreciated. -- Thank you Dave |
Error can't Find File
As ALWAYS, post YOUR code for comments
if day(date)=1 then do this else do that end if -- Don Guillett Microsoft MVP Excel SalesAid Software "Dave" wrote in message ... Hi, I have a macro that opens a file and pulls any outstanding tasks from the previous day. I have a problem when it is a new month because the previous month's file is called MyFileMarch2010. The macro now looks for MyFileApril2010. How do I capture the error and look for the previous month's file if it is the first business day of the month? Any help or suggestions is appreciated. -- Thank you Dave |
Error can't Find File
Or you could just build the name correctly.
Dim myDate as date dim myFileName as string dim wkbk as workbook dim myPath as string mypath = "C:\yourpathhere\" 'include the trailing backslash mydate = date - 1 'yesterday 'fix the extension to match .xlsx or .xlsm or ... myfilename = "myfile" & format(mydate, "mmmmyyyy") & ".xls" set wkbk = nothing on error resume next set wkbk = workbooks.open(filename:=mypath & myfilename) on error goto 0 if wkbk is nothing then msgbox myfilename & " wasn't found in: " & mypath exit sub end if ....code to work on wkbk goes here Dave wrote: Hi, I have a macro that opens a file and pulls any outstanding tasks from the previous day. I have a problem when it is a new month because the previous month's file is called MyFileMarch2010. The macro now looks for MyFileApril2010. How do I capture the error and look for the previous month's file if it is the first business day of the month? Any help or suggestions is appreciated. -- Thank you Dave -- Dave Peterson |
All times are GMT +1. The time now is 07:03 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com