Xin hỏi về mở file

chuongna37

Yêu THVBA
Mã:
sub test()

if "C:\dowload\text.xlsx" = True then
   msgbox "file da co"
End if
end sub
chào mọi người ý mình muốn diễn đạt là ví dụ trong đường dẫn trên đã có file text.xlsx rồi thì sẽ hiện thông báo file đã có ạ , mong được mọi người giúp đỡ
 

lyly

Nghiện THVBA
Sub Ktfile ()

Dim strFileName As String
Dim strFileExists As String

strFileName = "C:\Users\Nikola\Desktop\VBA articles\Test File Exists.xlsx"
strFileExists = Dir(strFileName)

If strFileExists = "" Then
MsgBox "file chua co”
Else
MsgBox “file da co “
End If

End Sub
 

chuongna37

Yêu THVBA
Sub Ktfile ()

Dim strFileName As String
Dim strFileExists As String

strFileName = "C:\Users\Nikola\Desktop\VBA articles\Test File Exists.xlsx"
strFileExists = Dir(strFileName)

If strFileExists = "" Then
MsgBox "file chua co”
Else
MsgBox “file da co “
End If

End Sub
cảm ơn tiền bối rất nhiều ạ !
 

HUONGLIEN7214

Yêu THVBA
Mã:
sub test()

if "C:\dowload\text.xlsx" = True then
   msgbox "file da co"
End if
end sub
chào mọi người ý mình muốn diễn đạt là ví dụ trong đường dẫn trên đã có file text.xlsx rồi thì sẽ hiện thông báo file đã có ạ , mong được mọi người giúp đỡ
Thử hàm UDF này xem sao
Mã:
Function FileExists(sFullPath As String) As Boolean
  FileExists = CBool(Len(Dir$(sFullPath)) > 0)
End Function
 
Top