Open Excel File - Not Found Message

Geezer

Registered User.
Local time
Tomorrow, 02:50
Joined
Jul 14, 2008
Messages
62
Have the following bit of code which opens an Excel file related to an entry in a form when the user clicks a button:

Private Sub Cmd_OpenExcel_CoreLoc_Click()

Dim CorePath
CorePath = "W:\Core Data\" & Me.WELLNAME.Value & ".xls"

Shell "C:\Program Files\Microsoft Office\OFFICE11\EXCEL.EXE """ & CorePath & "", vbNormalFocus

End Sub

However, if there is no file found Excel still opens and spits out it's own error message.

Is there any way to stop Excel opening if the file doesn't exist and Access giving it's own "not found" type message? I'm sure there is but I have no idea how to go about it.

Would appreciate any help and pointers.

Cheers,

Geezer
 
Look in VBA Help at the Dir() function, which you can use to test if the Excel file exists. Then you only run the Shell bit if it does.
 

Users who are viewing this thread

Back
Top Bottom