VBA Express Forum  




Go Back   VBA Express Forum > VBA Code & Other Help > Excel Help
     Feedback     
Register FAQ Members Arcade Knowledge Base Training Articles Consulting

Reply
 
Thread Tools Display Modes
Old 07-17-2008, 10:44 AM   #1
eddynutz

 
Joined: Jul 2008
Posts: 2
Kb Entries: 0
Articles: 0
Solved: Run-time error '53': File Not Found

I have a workbook that opens txt files in worksheets, one file per sheet.
i use Logfiles = ThisWorkbook.Path so that where it searches within the directory the workbook is located. Works fine when I open excel and navigate to the directory where the workbook exist. When I click directly on the file and I run the macro I get a "Run-time error '53': File Not Found"

VBA:
Sub Log_Cleaner() Dim numfiles As String DeleteAll FileLoc = ThisWorkbook.Path FileCountA (FileLoc) End Sub Function FileCountA(Path As String) As Long Dim strTemp As String Dim lngCount As Long Dim C3Po As String Sheets("Variables").Select C3Po = Range("C3").Value If C3Po = "" Then C3Po = "*.*" End If strTemp = Dir(Path & "\" & C3Po) If strTemp = "" Then MsgBox "No files found that fit Search criteria", , "CM MESSAGE" Exit Function End If ImportTextFile strTemp, "!@#", 0 Do While strTemp <> "" lngCount = lngCount + 1 strTemp = Dir If strTemp = "" Then Exit Function End If ImportTextFile strTemp, "!@#", lngCount Loop End Function
VBA tags courtesy of www.thecodenet.com

Last edited by eddynutz : 07-17-2008 at 11:08 AM.

Local Time: 02:31 AM
Local Date: 05-22-2013

 
Reply With Quote Top
Old 07-17-2008, 09:58 PM   #2
JimmyTheHand
 
JimmyTheHand's Avatar

 
Joined: Sep 2006
Posts: 534
Kb Entries: 0
Articles: 0
Hi and welcome to VBAX

I guess the root of the problem is that Dir function returns only the filename, not a full path. So you probably need to change
VBA:
ImportTextFile strTemp, "!@#", 0 ImportTextFile strTemp, "!@#", lngCount
VBA tags courtesy of www.thecodenet.com
to
VBA:
ImportTextFile Path & "\" & strTemp, "!@#", 0 ImportTextFile Path & "\" & strTemp, "!@#", lngCount
VBA tags courtesy of www.thecodenet.com


HTH

Jimmy

PS1: I say 'probably' because I don't see the code of Sub ImportTextFile, or the declaration of FileLoc.
PS2: C3Po is a funny name for a variable


-------------------------------------------------
The more details you give, the easier it is to understand your question. Don't save the effort, tell us twice rather than not at all. The amount of info you give strongly influences the quality of answer, and also how fast you get it.

Local Time: 08:31 AM
Local Date: 05-22-2013
Location:

 
Reply With Quote Top
Old 07-18-2008, 06:38 AM   #3
eddynutz

 
Joined: Jul 2008
Posts: 2
Kb Entries: 0
Articles: 0
Thanks for the welcome and thanks for the solution, great catch! C3Po was to remind the cell i was using to stuff the variable, C3 why not Po... Thanks again!
eddy

Local Time: 02:31 AM
Local Date: 05-22-2013

 
Reply With Quote Top
Old 07-18-2008, 12:11 PM   #4
mdmackillop
 
mdmackillop's Avatar
Administrator
VP-Knowledge Base

 
Joined: May 2004
Posts: 12,494
Kb Entries: 56
Articles: 2
Hi Eddy,
Welcome to VBAX.
When you post code, you can format it as shown by selecting it and clicking the VBA button. It makes it more readable.
Regards
MD


MVP (Excel 2008-2010)

"Provide sample data and layout if you want a quicker solution." - MD


To help indent your macros try Smart Indent

Please remember to mark threads 'Solved'

Local Time: 07:31 AM
Local Date: 05-22-2013
Location:

 
Reply With Quote Top
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -7. The time now is 11:31 PM.


Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Copyright © 2004 - 2012 VBA Express