LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Cannot find file - code error

dir(...) will return the name of the file--not including the path.

Try changing:
Set mybook = Workbooks.Open(filnames, , True)
to
Set mybook = Workbooks.Open(mypath & filnames, , True)

Depending on what myPath is, it may work the way you want.

keri wrote:

Hi,

I have the code below that opens each file in a folder, finds a value
and returns it to another sheet. However I am having a problem with
the code.

rnum = 1
Dim wkb As Workbooks
Dim filnames
filnames = Dir(mypath & "*" & ".xls")
Do While filnames < ""
Set mybook = Workbooks.Open(filnames, , True)
For Each sh In mybook.Worksheets
Set sourcerange = sh.Range("a100:p1000")
With sourcerange
Set rng = .Find(WHAT:="TOTAL")
If Not rng Is Nothing Then
basebook.Sheets("sheet1").cells(rnum, "B").Value = mybook.Name
basebook.Worksheets("SHEET1").cells(rnum, "C").Value =
rng.Offset(0, 1).Value
rnum = rnum + 1
Else
'do nothing
End If
End With
Next sh
mybook.Close savechanges:=False
Loop
End If

I get a runtime error '1004'
'ORDER21107.XLS' could not be found.Check the spelling of the file
name, and verify that the file location is correct.

(This debugs on the line
Set mybook = Workbooks.Open(filnames, , True))

I have checked the path is correct (and I know it must be as the error
is returning a filename in the correct folder) so it seems to be
another problem to this.

Any help would be appreciated before I pull all my hair out!


--

Dave Peterson
 
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
Error code - Could not decrypt file Bogdan Excel Programming 5 March 11th 07 11:12 PM
Find the Error in my Code Please Christine Excel Programming 4 May 15th 06 11:47 AM
Can't seem to find the error with this code matelot Excel Programming 4 January 4th 06 02:10 AM
Code To find and run an EXE file out side of the Excel A-Design Excel Programming 5 October 6th 04 01:06 PM
Cant get my code work. Find file or create it Poseilus Excel Programming 1 October 12th 03 03:42 PM


All times are GMT +1. The time now is 06:39 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"