title: vba search part of a file name to see if file exists?
body: <p>I have several text files (.txt) all called "Log" followed by a date like so (11-2014) and a random number like "34450"</p>
  
  <p>so my folder directory (P:) looks like:</p>
  
  <pre><code>Log (11-2014) 12234.txt
  Log (10-2014) 45546.txt
  Log (08-2014) 686868.txt
  Log (11-2014) 343434.txt
  </code></pre>
  
  <p>what I want to do is use vba code to count all occurrences where the log files contain the same month and year of todays date. </p>
  
  <p>so today's month is 11 and todays year is 2014 </p>
  
  <p>so I want to count all log files where the date bit of the file name "(11-2014)" matches the month and year of the current date/today's date.</p>
  
  <p>here's what I've tried but it doesn't work, I keep getting "found" even when the file doesn't exist, please could someone show me what im doing wrong?</p>
  
  <pre><code> Dim iMonth As Integer
      Dim iYear As Integer
  
      Dim target As String
      iMonth = Month(Date)
      iYear = Year(Date)
  
      thefile = "P:\Log *(" &amp; iMonth &amp; "-" &amp; iYear &amp; ")"
      If thefile &gt; 0 Then
  
      MsgBox "Found"
  
      Else
  
      MsgBox "Not"
  
      End If
  </code></pre>