![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Board Regular
Join Date: Feb 2002
Location: England
Posts: 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 |
|
|
|
|
|
#2 |
|
Banned
Join Date: Feb 2002
Posts: 1,582
|
Hi Matt
Full ifo here: http://www.ozgrid.com/VBA/IsWorkbookOpen.htm 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 |
|
|
|
|
|
#3 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Bogota, Colombia
Posts: 11,927
|
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 |
|
|
|
|
|
#4 |
|
Board Regular
Join Date: Feb 2002
Location: England
Posts: 212
|
Thanks again Dave
|
|
|
|
|
|
#5 |
|
Board Regular
Join Date: Feb 2002
Location: England
Posts: 212
|
Thanks Juan
|
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|