ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Check File Existence (https://www.excelbanter.com/excel-programming/361034-check-file-existence.html)

Catalin[_2_]

Check File Existence
 
Hi all. How do I check in VBA Excel the existence of a specified file in a
specified directory and display its status. Thanks

Norman Jones

Check File Existence
 
Hi Catalin,

Try:
'=============
Public Function FileExists(sPath As String, _
Optional sFName As String) As Boolean
FileExists = Len(Dir(sPath & sFName)) 0
End Function
'<<=============

An example of usage might be:
'=============
Sub TestIt()
MsgBox FileExists("C:\MyFolder\", "aBook.xls")
End Sub
'<<=============


---
Regards,
Norman



"Catalin" wrote in message
...
Hi all. How do I check in VBA Excel the existence of a specified file in a
specified directory and display its status. Thanks




Catalin[_2_]

Check File Existence
 
many thanks. it does work, but I've got another question: as the message box
returns true or false how can I pass this result to a variable?

"Norman Jones" wrote:

Hi Catalin,

Try:
'=============
Public Function FileExists(sPath As String, _
Optional sFName As String) As Boolean
FileExists = Len(Dir(sPath & sFName)) 0
End Function
'<<=============

An example of usage might be:
'=============
Sub TestIt()
MsgBox FileExists("C:\MyFolder\", "aBook.xls")
End Sub
'<<=============


---
Regards,
Norman



"Catalin" wrote in message
...
Hi all. How do I check in VBA Excel the existence of a specified file in a
specified directory and display its status. Thanks





Norman Jones

Check File Existence
 
Hi Catalin,

Try:

'=============
Sub Testit()
Dim blExists As Boolean

blExists = FileExists("C:\MyFolder\", "aBook.xls")
End Sub
'<<=============


---
Regards,
Norman



"Catalin" wrote in message
...
many thanks. it does work, but I've got another question: as the message
box
returns true or false how can I pass this result to a variable?

"Norman Jones" wrote:

Hi Catalin,

Try:
'=============
Public Function FileExists(sPath As String, _
Optional sFName As String) As Boolean
FileExists = Len(Dir(sPath & sFName)) 0
End Function
'<<=============

An example of usage might be:
'=============
Sub TestIt()
MsgBox FileExists("C:\MyFolder\", "aBook.xls")
End Sub
'<<=============


---
Regards,
Norman



"Catalin" wrote in message
...
Hi all. How do I check in VBA Excel the existence of a specified file
in a
specified directory and display its status. Thanks







Francisco MTY

Check File Existence
 
1.-
Revisa este link:

WD2000: Función VBA para comprobar si archivo o documento están abiertos

http://support.microsoft.com/kb/209189/es


2.-

existe.bat

@echo off
del /q c:\ok.txt
if exist "LA RUTA DE TU ARCHIVO & NOMBRE DEL MISMO" (
echo "El archivo existe" c:\ok.txt
) else (
echo "El archivo no existe" c:\ok.txt )
@echo on


sub existe()
Shell ("c:\existe.bat")
Open "c:\ok.txt" For Input As #1
Do Until EOF(1)
Line Input #1, vartexto
MsgBox vartexto
Loop
Close #1
end sub()



Catalin[_2_]

Check File Existence
 
MANY THANKS

"Norman Jones" wrote:

Hi Catalin,

Try:

'=============
Sub Testit()
Dim blExists As Boolean

blExists = FileExists("C:\MyFolder\", "aBook.xls")
End Sub
'<<=============


---
Regards,
Norman



"Catalin" wrote in message
...
many thanks. it does work, but I've got another question: as the message
box
returns true or false how can I pass this result to a variable?

"Norman Jones" wrote:

Hi Catalin,

Try:
'=============
Public Function FileExists(sPath As String, _
Optional sFName As String) As Boolean
FileExists = Len(Dir(sPath & sFName)) 0
End Function
'<<=============

An example of usage might be:
'=============
Sub TestIt()
MsgBox FileExists("C:\MyFolder\", "aBook.xls")
End Sub
'<<=============


---
Regards,
Norman



"Catalin" wrote in message
...
Hi all. How do I check in VBA Excel the existence of a specified file
in a
specified directory and display its status. Thanks








All times are GMT +1. The time now is 10:12 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com