Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Run time error 53, cannot find file | Excel Programming | |||
1004 error - can't find text file to refresh ... | Excel Programming | |||
Excel cannot find file error | Excel Programming | |||
Cannot find file - code error | Excel Programming | |||
Automation Error: The system cannot find file specified | Excel Programming |