title: How to copy data from another workbook (excel)?
body: <p>I already have a macro that creates sheets and some other stuff. After a sheet has been created do I want to call another macro that copies data from a second excel (its open) to first and active excel file.</p>
  
  <p>First I want to copy to headers, but I cant get that to work - keep getting errors.</p>
  
  <pre><code>Sub CopyData(sheetName as String)
    Dim File as String, SheetData as String
  
    File = "my file.xls"
    SheetData = "name of sheet where data is"
  
    # Copy headers to sheetName in main file
    Workbooks(File).Worksheets(SheetData).Range("A1").Select  # fails here: Method Select for class Range failed
    Workbooks(File).Worksheets(SheetData).Range(Selection, Selection.End(xlToRight)).Select
    Workbooks(File).Worksheets(SheetData).Selection.Copy ActiveWorkbook.Sheets(sheetName).Cells(1, 1)
  End Sub
  </code></pre>
  
  <p>What is wrong ?</p>
  
  <p>I really want to avoid having to make "my file.xls" active.</p>
  
  <p>Edit: I had to give it up and copy the SheetData to target file as a new sheet, before it could work.
  <a href="https://stackoverflow.com/questions/482889/how-to-find-and-select-multiple-rows-with-macro-excel">Find and select multiple rows</a></p>