View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 6,953
Default Exit Sub if file/path not found

if dir(sPath & sFilename) = "" then exit sub

--
Regards,
Tom Ogilvy


"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