J
Junior728
Hi,
How do i make sure that only if both of the If statements are met, then the
file will be open? I tried, but somehow only the latest file will be opened,
when the filename does not start with the FName.
As below:
Not sure if it works:
Sub Test()
Const Path = "H:\My WorkStation\PRCD"
Dim FName As String
Dim FSO As Object
Dim Folder As Object
Dim strName As String
Dim oFile As Object
Set FSO = CreateObject("Scripting.FileSystemObject")
Set Folder = FSO.GetFolder(Path)
FName = "PRCD"
For Each x In Folder.Files
If x.DateLastModified > dteDate Then
dteDate = x.DateLastModified
strName = x.Name
End If
If UCase(x.Name) Like UCase(FName & "*" & ".xls") Then
Workbooks.Open (Path & Application.PathSeparator _
& x.Name)
End If
'Exit For
N = N + 1
Next x
MsgBox N & " files" & vbCr & strName & " _ is latest file " _
& vbCr & "Dated _ " & dteDate 'Check if it works
End Sub
How do i make sure that only if both of the If statements are met, then the
file will be open? I tried, but somehow only the latest file will be opened,
when the filename does not start with the FName.
As below:
Not sure if it works:
Sub Test()
Const Path = "H:\My WorkStation\PRCD"
Dim FName As String
Dim FSO As Object
Dim Folder As Object
Dim strName As String
Dim oFile As Object
Set FSO = CreateObject("Scripting.FileSystemObject")
Set Folder = FSO.GetFolder(Path)
FName = "PRCD"
For Each x In Folder.Files
If x.DateLastModified > dteDate Then
dteDate = x.DateLastModified
strName = x.Name
End If
If UCase(x.Name) Like UCase(FName & "*" & ".xls") Then
Workbooks.Open (Path & Application.PathSeparator _
& x.Name)
End If
'Exit For
N = N + 1
Next x
MsgBox N & " files" & vbCr & strName & " _ is latest file " _
& vbCr & "Dated _ " & dteDate 'Check if it works
End Sub