Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 44
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
& combine two array statements Paul Moles Excel Worksheet Functions 3 December 9th 09 11:24 AM
Can I combine IF/AND/OR statements? CJOHNSO92 Excel Worksheet Functions 8 March 24th 09 03:10 AM
Combine cells with the same reference and combine quantities brandon Excel Discussion (Misc queries) 2 September 17th 08 05:44 PM
how do I combine multiple IF statements to come up with 1 value? Johanna Excel Worksheet Functions 6 April 29th 07 06:51 PM
Combine Intersect Range in If statements Ben Dummar Excel Discussion (Misc queries) 5 March 22nd 07 10:37 PM


All times are GMT +1. The time now is 06:58 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"