Hi
For Each x In Folder.Files
If x.DateLastModified > dteDate And Ucase(x.Name) Like UCase(FName & "*" &
".xls") Then
Workbooks.Open (Path & Application.PathSeparator _
& x.Name)
End If
HTH
Cordially
Pascal
"Junior728" <(E-Mail Removed)> a écrit dans le message de
news:
6655A0FE-18CB-4F73-83B7-(E-Mail Removed)...
> 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
>
>