Checking to see if a file exists

Matt

Board Regular
Joined
Feb 16, 2002
Messages
212
I'm trying to write some code to check if a file exists in a particular directory, if the file does exist, I want to bring up a message box confirming that the file exists. I would appreciate any suggestions.

Thanks

Matt
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Hi Matt


Full ifo here: http://www.ozgrid.com/VBA/IsWorkbookOpen.htm


Rich (BB code):
Sub DoesWorkBookExist()
'''''''''''''''''''''''''''''''
'Written by http://www.Ozgrid.com

'Test to see if a Workbook exists
''''''''''''''''''''''''''''''''
Dim i As Integer

	With Application.FileSearch
		.LookIn = "C:MyDocuments"
		'* represents wildcard characters
		.FileName = "Book*.xls" 
			If .Execute > 0 Then 'No Workbook
			      MsgBox "There is no Workbook."
			Else 'There is a Workbook
			      MsgBox "The Workbook does not exist"
			End If
	End With
End Sub
 
Upvote 0
Another option:

Sub T()
Dim Pth as String

Pth = "C:My DocumentsTestFile.xls"

If Len(Dir(Pth)) > 0 then
'Found It !
Else
MsgBox "Coudln't find it"
End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,415
Messages
6,119,382
Members
448,889
Latest member
TS_711

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top