Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Combine 2 IF STatements
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 |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Combine 2 IF STatements
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 UCase(x.Name) Like UCase(FName & "*" & ".xls") Then If x.DateLastModified dteDate Then dteDate = x.DateLastModified strName = x.Name Workbooks.Open Path & Application.PathSeparator _ & x.Name End If 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 -- --- HTH Bob (there's no email, no snail mail, but somewhere should be gmail in my addy) "Junior728" wrote in message ... 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 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
& combine two array statements | Excel Worksheet Functions | |||
Can I combine IF/AND/OR statements? | Excel Worksheet Functions | |||
Combine cells with the same reference and combine quantities | Excel Discussion (Misc queries) | |||
how do I combine multiple IF statements to come up with 1 value? | Excel Worksheet Functions | |||
Combine Intersect Range in If statements | Excel Discussion (Misc queries) |