title: How to select randomly change XLS workbook filename using VBA
body: <p>A program create and open XLS workbook with random filename ending. E.g : Jobs, Jobs(0-500), Jobs(0-599). This workbook was not yet saved. Saving the workbook was not required.</p>
  
  <pre><code>Windows("Jobs(0-178)").Activate
  </code></pre>
  
  <p>this VBA only work if the filename is same.</p>
  
  <p>I wanted to create Excel Macro to copy the data from Job(0-500) to my workbook.</p>
  
  <p>Can someone help?</p>
  
  <p>Thanks.</p>
  
  <p>Update : </p>
  
  <p>Currently, my VBA only can read the wordbook name if the filename is specific, which is "Jobs in Lab". If the output filename changed, E.G : "Jobs in Lab(0-123), the macro could not read it.</p>
  
  <p>Below is my current VBA,</p>
  
  <pre><code>Sub StartMacro()
  Windows("Jobs in Lab").Activate
  Range("A1:P500").Select
  Selection.Copy
  Windows("Jobs in Lab - Macro.xlsm").Activate  
  End Sub
  </code></pre>
  
  <p>I've tried using </p>
  
  <pre><code>Sub Sample()
      Dim wb As Workbook
  
      For Each wb In Application.Workbooks
          If wb.Name Like "Jobs in Lab*" Then
              wb.Activate
              Exit Sub
          End If
      Next wb
  End Sub
  </code></pre>
  
  <p>But, this VBA only work if i save the workbook first.</p>