PC Review


Reply
Thread Tools Rate Thread

Combine 2 IF STatements

 
 
=?Utf-8?B?SnVuaW9yNzI4?=
Guest
Posts: n/a
 
      3rd Oct 2007
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 With Quote
 
 
 
 
papou
Guest
Posts: n/a
 
      3rd Oct 2007
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
>
>



 
Reply With Quote
 
Bob Phillips
Guest
Posts: n/a
 
      3rd Oct 2007
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" <(E-Mail Removed)> wrote in message
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
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can I combine IF/AND/OR statements? CJOHNSO92 Microsoft Excel Worksheet Functions 8 24th Mar 2009 03:10 AM
Combine Statements =?Utf-8?B?Xw==?= Microsoft Access Reports 1 6th Aug 2005 08:04 PM
Combine (2) If Statements Dave Elliott Microsoft Access Forms 1 14th Dec 2004 07:07 PM
Combine (2) If Statements ! Dave Elliott Microsoft Access Forms 9 7th Dec 2004 03:08 PM
Combine two if then statements...help =?Utf-8?B?TQ==?= Microsoft Excel Worksheet Functions 0 22nd Oct 2004 09:13 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:23 PM.