title: How to open an excel workbook in vba using string variable
body: <p>I have an array of Excel files. I want to assign the file to a string variable and then assign it to Workbooks.Open to open it. I get this error "Application-defined or object-defined error. Any idea where I might be going wrong?</p>
  
  <p>This is my code:  </p>
  
  <pre><code>Dim x As Workbook
  Dim xFileName As String
  Dim WkBk As Integer
  Dim MyArrayOne as Integer
  WkBk = 0
  
      MyArray1 = Array("filename1", filename2", filename3, filename4")
  
  Do While Count &lt;&gt; MyArrayOne
  
      xFileName = MyArray1(WkBk)
      Set x = Workbooks.Open(xFileName)
      WkBk = WkBk + 1
  Loop
  </code></pre>