ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   check to see a file is existed (https://www.excelbanter.com/excel-programming/372150-check-see-file-existed.html)

2007-User

check to see a file is existed
 
Hi Guys,

How Can I :
1- check to see a file (non excel file) is existed?
2- like I do double click on a file (on windows area) to open it with its
application, how can I do the same thing with VBA?

Thanks in advance



RB Smissaert

check to see a file is existed
 
To check if a file exists use a function like this:

Function bFileExists(ByVal sFile As String) As Boolean

Dim lAttr As Long

On Error Resume Next
lAttr = GetAttr(sFile)
bFileExists = (Err.Number = 0) And ((lAttr And vbDirectory) = 0)
On Error GoTo 0

End Function


To open a file look at Shell in the VBA help.


RBS


"2007-User" wrote in message
...
Hi Guys,

How Can I :
1- check to see a file (non excel file) is existed?
2- like I do double click on a file (on windows area) to open it with its
application, how can I do the same thing with VBA?

Thanks in advance



2007-User

check to see a file is existed
 
Thanks,!

"RB Smissaert" wrote in message
...
To check if a file exists use a function like this:

Function bFileExists(ByVal sFile As String) As Boolean

Dim lAttr As Long

On Error Resume Next
lAttr = GetAttr(sFile)
bFileExists = (Err.Number = 0) And ((lAttr And vbDirectory) = 0)
On Error GoTo 0

End Function


To open a file look at Shell in the VBA help.


RBS


"2007-User" wrote in message
...
Hi Guys,

How Can I :
1- check to see a file (non excel file) is existed?
2- like I do double click on a file (on windows area) to open it with its
application, how can I do the same thing with VBA?

Thanks in advance






All times are GMT +1. The time now is 01:39 PM.

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