Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,388
Default 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
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Run time error 53, cannot find file GaryF[_2_] Excel Programming 4 November 23rd 08 06:24 PM
1004 error - can't find text file to refresh ... LeAnn Excel Programming 2 October 4th 07 01:34 AM
Excel cannot find file error Joanne Excel Programming 4 July 29th 07 10:58 PM
Cannot find file - code error keri Excel Programming 2 June 30th 07 03:21 PM
Automation Error: The system cannot find file specified Shilpa[_2_] Excel Programming 3 August 25th 06 09:05 AM


All times are GMT +1. The time now is 07:24 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"