LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 310
Default File not found when opening

Hello all!

I have set up a function that loops through all the files in a certain
folder and find & open a prior month's file and return that file name.
However, when I run the function sometimes (not all the time) I get a
run-time error 1004, file not found. I don't understand why this is since
the loop is only running through the file names in that folder. The file to
be opened is not in use by another user either. My code is below. Any
insight would be amazing. Thanks.

--
Cheers,
Michelle
"Anyone who says he can see through women is missing a lot." Groucho Marx

Sub test()
Const acct As String = "xxx"
Dim tmp As String

tmp = PrevFile(acct)
End Sub

Function PrevFile(acct As String)
Dim myPath As String, myName As String, folder As String
Dim m As Variant
Dim y As Integer
Dim tmp As Variant

m = Month(ThisWorkbook.Worksheets(1).Range("B3").Value ) - 1
If m < 10 Then
m = "0" & m & "_"
Else
m = m & "_"
End If
y = Year(ThisWorkbook.Worksheets(1).Range("B3").Value)
folder = y & " PC Reports"
myPath = "G:\Reports New\" & folder & "\*.xls"
myName = Dir(myPath)
Do
If InStr(1, myName, m, vbTextCompare) 0 And InStr(1, myName, acct,
vbTextCompare) 0 Then
Application.DisplayAlerts = False
Workbooks.Open Filename:=myName, UpdateLinks:=False
Application.DisplayAlerts = True
Exit Do
End If
myName = Dir
MsgBox myName
Loop While myName < ""
PrevFile = myName
End Function
 
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
Stop a user from opening Excel if the Add-in is not found C#_Programmer Excel Programming 0 September 13th 07 03:46 AM
file not found when opening the file bribri Excel Discussion (Misc queries) 2 September 1st 06 11:00 PM
VB Error 'File Not Found' when opening Excel Sarah Braun Excel Programming 2 December 19th 05 07:56 PM
Excel opening with Visual Basiic File not Found Error?? Help!!! jbsand1001 Excel Discussion (Misc queries) 1 May 27th 05 03:05 PM
Exclamation message box opening Excel - Archive not found! Martin Los[_3_] Excel Programming 2 March 30th 05 03:37 PM


All times are GMT +1. The time now is 08:24 PM.

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

About Us

"It's about Microsoft Excel"