LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default Exit Sub if file/path not found

Use a FileSystemObject to test the validity of the Path/Filename...

Dim objFSO as Object

Set objFSO = CreateObject("Scripting.FileSystemObject")

If objFSO.FileExists(sPath & sFileName) then

...open the workbook here and finish off your code.

Else:

...add code here if file does not exist.

End If

End Sub
--
3c


"EMoe" wrote:


Hello Programmers!!!

I have a code (posted Below) that finds a file by Path & Name, and
retrieves a number from a specific cell, then places it in the open
workbook named results.

How do add that if the Path or filename isn't found then do nothing (or
exit the sub). Or maybe for an indication place the Letters "NF" (for
Not Found) in the cell where the number is suppose to go. I don't want
any error messages or boxes to pop up; only quit the macro if the
file/path name(s) are incorrect.

CODE:

Public Sub GetValue()

Application.ScreenUpdating = False
Dim sFileName As String
Dim sPath As String

sPath = Range("AE4").Value
sFileName = Range("AE6").Value

If Not Right(sFileName, 4) < ".xls" Then
sFileName = sFileName & ".xls"
End If

Workbooks.Open Filename:=sPath & sFileName

Sheets("Auto Place Sheet").Activate
Range("B371").Copy
Windows("Results.xls").Activate
Range("M29").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
Windows("Results.xls").ActivatePrevious
Application.CutCopyMode = False
ActiveWorkbook.Close
Application.ScreenUpdating = True

End Sub

Thanks,
EMoe


--
EMoe
------------------------------------------------------------------------
EMoe's Profile: http://www.excelforum.com/member.php...o&userid=23183
View this thread: http://www.excelforum.com/showthread...hreadid=572305


 
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
Formula too long - new file path is shorter than old file path - Excel 2003 Greg J Excel Worksheet Functions 1 November 22nd 06 05:16 PM
Path not found error EAB1977 Excel Programming 6 December 9th 05 04:05 PM
Path Not Found Michael[_22_] Excel Programming 2 November 29th 03 04:21 PM
If no FIND value is found, then a Msgbox to say so and exit sub L. Howard Kittle[_2_] Excel Programming 3 September 23rd 03 08:46 PM
Which Path not found? Tod Excel Programming 3 August 2nd 03 02:03 PM


All times are GMT +1. The time now is 09:26 AM.

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"